我有与MySQL数据库的经验,并成功地连接到他们与几个项目。无法连接到SQL Server 2008从PHP
现在,我在连接到SQL Server 2008时遇到了问题。工作原理:<?php phpinfo(); ?>
和sqlsrv和pdo_sqlsrv部分显示在此页面上。下面是我使用的连接代码:
<?php
$serverName = "serverName\sqlexpress"; //serverName\instanceName
$connectionInfo = array("Database"=>"dbName", "UID"=>"userName", "PWD"=>"password");
$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));
}
?>
此代码是直接从php.net这里:http://www.php.net/manual/en/function.sqlsrv-connect.php。我做的唯一更改是用##。#。#。##替换serverName \ sqlexpress。并更改:dbName,用户名,密码。
下面是结果,当我运行的连接上面的代码:
Parse error: syntax error, unexpected '$serverName' (T_VARIABLE) in C:\inetpub\quote.myWebsite.com\index.php on line 23
即使我像这样运行一些简单:
<?php $myVariable = "someString"; ?>
我得到同样的类型分析错误的:
Parse error: syntax error, unexpected '$myVariable' (T_VARIABLE) in C:\inetpub\quote.myWebsite.com\index.php on line 23
为什么我在我的PHP代码中收到错误?
这与SQL服务器没有任何关系,它是纯粹的PHP语法错误。 –
此代码中没有'23'行,你如何使用它?此外,该链接似乎包含一个端口号'$ serverName =“serverName \ sqlexpress,1542”; // serverName',你没有。 –
index.php文件的第23行是什么? – Robbert