php sql server 跨服务器关联查询
请教诸君。在PHP里面能不能使用SQL Server的跨服务器查询?我有个SQL语句是跨服务器的关联查询,在SQL Server的查询分析器里面是可以正常运行的,但是同样的语句放在PHP里面(用的PDO)就报错(错误码:7405)。不知道是PDO的驱动不支持还是什么原因,求不吝指教。感谢!
错误提示信息如下;
SQLSTATE[HY000]: General error: 7405 General SQL Server error: Check messages from the SQL Server [7405] (severity 16)
主要代码如下;
$options = array(
PDO::ATTR_CASE => PDO::CASE_NATURAL,
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_ORACLE_NULLS => PDO::NULL_NATURAL,
PDO::ATTR_STRINGIFY_FETCHES => false,
);
$olddb_db_connect = new PDO($olddb_dsn, $db_config['OLD_DB']['DB_USER'], $db_config['OLD_DB']['DB_PWD'],$options);
$olddb_db_connect->exec("exec sp_configure 'show advanced options',1");
$olddb_db_connect->exec("reconfigure");
$olddb_db_connect->exec("exec sp_configure 'Ad Hoc Distributed Queries',1");
$olddb_db_connect->exec("reconfigure");
$result = $olddb_db_connect->query(
"SELECT T1.* FROM (SELECT thinkphp.*, ROW_NUMBER() OVER ( ORDER BY ctime DESC) AS ROW_NUMBER FROM (SELECT posts.broker_id,users.COMP_NO,users.DEPT_NO,users.USER_NAME,posts.content,posts.ctime FROM w_microshop_posts posts INNER JOIN OPENDATASOURCE(
'SQLOLEDB',
'Data Source=[这是ip和端口];uid=sa;pwd=[这是密码]'
).hft_centerdb_CD.dbo.FUN_USERS AS users ON posts.broker_id=users.ARCHIVE_ID WHERE (
users.COMP_NO='A01'
AND
users.DEPT_NO IN ('A1','A2','A3','A4','A5','A6','A7','A8','A9','B0','B1','B2','B3','B4','B5','B6','B7','B8','B9')
AND
posts.post_id = (SELECT TOP 1 post_id FROM w_microshop_posts where broker_id=posts.broker_id order by ctime DESC)
AND
EXISTS(SELECT id FROM w_microshop_attach WHERE broker_id=posts.broker_id AND model='Posts')
AND
users.USER_WRITEOFF=0 ) ) AS thinkphp) AS T1 WHERE (T1.ROW_NUMBER BETWEEN 0 + 1 AND 0 + 25)"
);
print_r($result->fetchAll());
maccon
9 years, 6 months ago