在尝试从 SQL Server 访问 MySql Server 的数据之后,我一直面临一个问题。这是我到目前为止所做的。1) 在我的 SQL Server 上安装 MySQL ODBC Driver 5.2w 2) 我按照本网站http://sql-articles.com/blogs/creating-linked-
上的说明从 Microsoft SQL Server Managment S (MSQLSMS) 创建了一个链接服务器
服务器到 mysql-from-sql-server/
现在,在我的 MSQLSMS 中,我打开了一个与名为“SERV1”的服务器的连接,我执行了以下查询,它可以正常工作。
SELECT
p.team_name,
p.fullname,
SUM( ISNULL(i.CallDurationSeconds, 0) ) AS totalTime
FROM OPENQUERY(SERVPHP, 'SELECT
CAST(t.name AS CHAR) AS team_name,
CAST(TRIM(REPLACE(CONCAT(su.first_name, " ", su.middle_name , " ", su.last_name), " ", " ")) AS CHAR) AS fullname,
CAST(su.login_user AS CHAR) AS username,
CAST(p.account_id AS UNSIGNED) AS account_id
FROM call_managment_system.phone_calls AS p
INNER JOIN call_managment_system.users AS su ON p.owner_id = su.user_id
INNER JOIN call_managment_system.teams AS t ON su.team_id = t.team_id
WHERE p.status = 2 AND t.client_id = 1 AND p.last_attempt_on BETWEEN "2013-01-01 08:00:00" AND "2013-04-30 07:00:00"
GROUP BY t.team_id, p.owner_id') AS p
INNER
JOIN OPENQUERY(SERVPHP, 'SELECT
CAST(cn.contact_number AS CHAR) AS phone_number,
CAST(cn.account_id AS UNSIGNED) AS account_id
FROM call_managment_system.contact_numbers AS cn
WHERE cn.contact_link = "Account"
UNION
SELECT CAST(cn2.contact_number AS CHAR) AS phone_number,
CAST(cn2.account_id AS UNSIGNED) AS account_id
FROM call_managment_system.contact_personal AS cp
INNER JOIN call_managment_system.contact_numbers AS cn2 ON cn2.person_id = cp.person_id AND cn2.contact_link = "Account" ') AS cn ON cn.account_id = p.account_id
INNER
JOIN I3_IC.dbo.CallDetail AS i ON p.username = i.LocalUserId AND RIGHT(i.RemoteNumber, 10) = cn.phone_number
WHERE i.I3TimeStampGMT BETWEEN '2013-01-01 08:00:00' AND '2013-04-30 07:00:00'
GROUP BY p.team_name, p.fullname
现在因为我使用 PHP 来执行这个查询。我已经完成了以下 1) 使用 PDO api 连接到我之前执行此查询的 SQL 服务器“SERV1”。2) 尝试执行上面列出的相同查询。但是这次我遇到了我无法解决的错误。
致命错误:未捕获的异常 'PDOException' 带有消息 'SQLSTATE[42000]:[Microsoft][SQL Server Native Client 10.0][SQL Server]无法初始化链接服务器“SERVPHP”的 OLE DB 提供程序“MSDASQL”的数据源对象
请注意,“SERVPHP”是运行我的 PHP 应用程序和运行 MySql Server 的服务器。“SERV1”如果我的 SQL 服务器在哪里运行并且我在哪里安装了 ODBC 驱动程序。
更多,当我从我的 PHP 应用程序以相同的方式运行此查询时,它可以工作
SELECT
LocalUserId AS loginName,
RemoteNumber AS PhoneNumber,
SUM(CallDurationSeconds) AS totalTalk
FROM CallDetail
WHERE LocalUserId = 'test' AND
I3TimeStampGMT BETWEEN '2013-01-01 08:00:00' AND '2013-04-30 07:00:00'
GROUP BY LocalUserId, RemoteNumber
为什么它现在有效?我需要什么才能让这个查询从我的 PHP 服务器执行?
谢谢