我使用ZendFramework和PHP版本5.4.12,我的操作系统是Windows 7。 我的连接参数是
resources.db.adapter = "sqlsrv"
resources.db.params.pdoType = "mssql"
但我有这个例外
Fatal error: Uncaught exception 'Exception' with message '[Microsoft][SQL Server Native Client 11.0]SQL Server Native Client 11.0 does not support connections to SQL Server 2000 or earlier versions.'
因为我使用的是最新的php驱动程序。
如何连接到MS SQL Server 2000(版本8.00.760)?
答案 0 :(得分:3)
我有一些仍在运行SQL Server 2000的数据库,我不想为其他人恢复到旧的驱动程序。经过一番探讨,这是我能提出的最好的解决方法:通过ADO使用OLEDB连接到SQL Server 2000数据库。 ADO是一个COM组件,因此您需要启用COM_DOT_NET
扩展名。
我已经验证这仍然适用于安装了Native Client 11的Windows Server 2008 R2下的PHP 5.4。
<?php
$conn = new COM("ADODB.Connection") or die("Cannot create ADO COM object");
$conn->Open("Provider=SQLOLEDB;Integrated Security=SSPI;Persist Security Info=True;Data Source=LOCALHOST;Initial Catalog=master");
//$conn->Open("Provider=SQLOLEDB;User ID=username;Password=password;Persist Security Info=True;Data Source=host.example.com;Initial Catalog=databasename");
$rs = $conn->Execute("SELECT 1 as Number,GetDate() as Date, CAST(0 as bit) as Boolean, 'hello world' as String");
$fieldnames = [];
$rows = [];
while (!$rs->EOF){
$fieldnames = []; // wasteful, redoing this each time
$thisrow = [];
for ($i=0;$i<($rs->Fields->Count);$i++) {
$field = $rs->Fields[$i];
$fieldname = (string) $field->Name;
$type = $field->Type;
// field->Type is the ADO type; due personal weakness I am only handling types I actually need
if ($type == 3 || $type == 20) {
$value = (integer) $field->Value;
} elseif ($type == 4 || $type==5) {
$value = (float) $field->Value;
} elseif ($type == 11) {
$value = (boolean) $field->Value;
} else {
$value = (string) $field->Value;
}
$thisrow[] = $value; //array by index
$thisrow[$fieldname] = $value; // array by name
$fieldnames[]=$fieldname;
}
$rows[] = $thisrow;
$rs->MoveNext();
}
$rs->Close();
$conn->Close();
echo "your fieldnames are, in column order:\n";
var_dump($fieldnames);
echo "your data is, in record order:\n";
var_dump($rows);
?>
注意:
待办事项:参数化查询。我希望我能将这些主机更新为SQL Server 2012 Express Edition而不是......
答案 1 :(得分:1)
因为您使用的是SQL Server Native Client(版本11)的版本2012,它不再支持SQL Server的2000版本。是的,这很遗憾。
要解决此问题,您应该下载可在此处找到的早期版本:http://www.microsoft.com/en-us/download/details.aspx?id=16978
寻找
部分Microsoft®SQLServer®2008R2 Native Client
它仍然无效,您需要先卸载2012版本。
如果仍无效,请查看此处:http://www.sqlservercentral.com/Forums/Topic1317581-2799-1.aspx