PHP错误:数组([0] => IMSSP [SQLSTATE] => IMSSP [1]

时间:2016-10-05 11:12:07

标签: php sqlsrv

运行我的PHP程序后,我收到错误如下:

  

数组([0] =>数组([0] => IMSSP [SQLSTATE] => IMSSP [1] => -49 [代码] => -49 [2] =>这扩展需要SQL Server的Microsoft ODBC驱动程序11。访问以下URL以下载适用于x86的SQL Server的ODBC驱动程序11:http://go.microsoft.com/fwlink/?LinkId=163712 [message] =>此扩展需要SQL Server的Microsoft ODBC驱动程序11。访问以下URL以下载适用于x86的SQL Server的ODBC驱动程序11:http://go.microsoft.com/fwlink/?LinkId=163712)[1] =>数组([0] => IM002 [SQLSTATE] => IM002 [1] => 0 [code] => 0 [2] => [Microsoft] [ODBC驱动程序管理器]未找到数据源名称且未指定默认驱动程序[message] => [Microsoft] [ODBC驱动程序管理器]数据源名称未找到并且没有指定默认驱动程序))

我已安装所有扩展并在PHP中启用。但我仍然遇到这个错误。

<?php


$serverName ="tcp:myserver.database.windows.net,1433";
$usr="username";
$pwd="password";
$db="SensorDataBase";

$connectionInfo = array("UID" => $usr, "PWD" => $pwd, "Database" => $db);

$conn = sqlsrv_connect($serverName, $connectionInfo);
if( $conn )
{
    echo "Connected";
}
else
{
    echo "Error As follows: ";
    die( print_r( sqlsrv_errors(), true));
}

$sql = "CREATE TABLE fyi_links ("
    . " id INT NOT NULL VARCHAR (6)" 
    . ", url VARCHAR(80) NOT NULL"
    . ", notes VARCHAR(1024)"
    . ", counts INT"
    . ", time DATETIME"
    . ")";
$res = sqlsrv_query($conn, $sql);
//$res = sqlsrv_query($sql,$conn);
if (!$res) {
    print('Table creation failed with error:\n');
    print("   ".sqlsrv_get_last_message()."\n");
}
else {
    print("Table fyi_links created.\n");
}  

mssql_close( $conn);

?>

1 个答案:

答案 0 :(得分:-1)

为了解决这个问题我做了以下工作,我进入了这个链接:https://microsoft.com/en-gb/download/details.aspx?id=3643,选择你的系统,如果是x86或x64,安装并测试。这解决了我的问题。