[英]PHP 5.3 and sqlsrv_connect
Deal All, i have follow issue: i would like to connect to ms sqlserver2008 with php function. 处理所有,我有以下问题:我想用php函数连接到ms sqlserver2008。 In the past it works fine with mssql_connect. 过去,它可以与mssql_connect一起正常工作。 Since i have updated to php 5.3 i have an array issue: 由于我已经更新到php 5.3,所以我遇到了数组问题:
Syntax: 句法:
$serverName = "sql server"; //serverName\instanceName, portNumber (default is 1433)
$connectionInfo = array( "db", "user", "pw");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
if( $conn ) {
echo "Connection established.<br />";
}else{
echo "Connection could not be established.<br />";
die( print_r( sqlsrv_errors(), true));
}
exit;
When i will show the page, i get this array error: 当我显示页面时,出现此数组错误:
Connection could not be established.
Array ( [0] => Array ( [0] => IMSSP [SQLSTATE] => IMSSP [1] => -8 [code] => -8 [2] => An
invalid connection option key type was received. Option key types must be strings.
[message] => An invalid connection option key type was received. Option key types must be strings. ) )
Maybe somebody has an idea ? 也许有人有主意? For this I would be very grateful 为此,我将非常感谢
我认为这是数组定义,请尝试以下操作:
$connectionInfo = array( "Database"=>"db", "UID"=>"user", "PWD"=>"pw");
Might be you are enclosing parameters into double quotes too. 可能是因为您也将参数括在双引号中。
Incorrect Syntax: 语法错误:
$connectionInfo = array("Database"=>"$this->db_name", "UID"=>"$this->user_name", "PWD"=>"$this->user_pwd");
$connectionInfo = array("Database=>$this->db_name", "UID=>$this->user_name", "PWD=>$this->user_pwd");
Correct Syntax: 正确的语法:
$connectionInfo = array("Database"=>$this->db_name, "UID"=>$this->user_name, "PWD"=>$this->user_pwd);
Complete Code Should be as below 完整代码应如下
<?php
class db_config{
private $server_name = "BITCODES\SQLEXPRESS";
private $user_name = "ERPSA";
private $user_pwd = "ERP@123";
private $db_name = "CANE_1718";
private $connectionInfo;
function db_connect(){
$this->connectionInfo = array("Database"=>$this->db_name, "UID"=>$this->user_name, "PWD"=>$this->user_pwd);
try{
$sql_connect = sqlsrv_connect($this->server_name,$this->connectionInfo);
if($sql_connect){
echo 'Server Connected';
}
else{
die(print_r(sqlsrv_errors()));
}
}
catch(Exception $x){
print_r($x);
}
}
} }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.