[英]How to connect PHP to SQL Server?
I'm trying to connect to SQL Server using PHP, I'm learning this language. 我正在尝试使用PHP连接到SQL Server,我正在学习这种语言。
I have read that probably a ODBC connection is the best, I have created mine ODBC but I don't know how to use it from PHP, so far I'm trying this: 我已经读过可能ODBC连接是最好的,我创建了我的ODBC,但我不知道如何从PHP使用它,到目前为止我正在尝试这个:
$server = 'MyServer\MyDB';
// Connect to MSSQL
$link = mssql_connect=($server, 'MyUser', '');
if (!$link) {
die('You cannot connect to MSSQL');
}
When running this I get this message: 运行时我收到此消息:
OBJECT NOT FOUND, ERROR 404.
OBJECT NOT FOUND,ERROR 404。
But ODBC test is fine. 但ODBC测试很好。
The SQL Server is located in the same PC, so maybe I don't need to input the IP. SQL Server位于同一台PC中,因此我可能不需要输入IP。
Is there anybody who can help? 有人可以提供帮助吗?
It appears you may have a typo. 看来你可能有一个错字。 Here's an example from the documentation :
以下是文档中的示例:
// Server in the this format: <computer>\<instance name> or
// <server>,<port> when using a non default port number
$server = 'KALLESPC\SQLEXPRESS';
// Connect to MSSQL
$link = mssql_connect($server, 'sa', 'phpfi');
if (!$link) {
die('Something went wrong while connecting to MSSQL');
}
You mistakenly placed an =
after mssql_connect
, attempting to make an assignment (as far as the interpreter is concerned). 您错误地在
mssql_connect
之后放置了一个=
,尝试进行分配(就解释器而言)。
As for using MSSql with PHP, have a look at the relevant mssql functions . 至于在PHP中使用 MSSql,请看一下相关的mssql函数 。 Next you would select your database , and then begin querying it .
接下来,您将选择您的数据库 ,然后开始查询它 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.