WAMP php ODBC连接“警告"
问题描述:
我在php中使用ODBC时遇到了问题(WAMP Server 2.5,PHP 5.5.12).
I have a problem with ODBC in php (WAMP Server 2.5, PHP 5.5.12).
当我尝试运行时:
$conn = odbc_connect("odbc_dsn", "user", "pwd");
if ($conn)
{
echo "Connection established.";
}
else
{
exit("Connection could not be established.");
}
我收到警告:
Warning: odbc_connect(): in C:\wamp\www\Concepts\index.php on line 29
Connection could not be established.
如果我将"odbc_dsn"更改为"fdbasdf"之类的其他名称(不存在),则会得到:
If I change the "odbc_dsn" to something else (that doesn't exist) like "fdbasdf" then I get:
Warning: odbc_connect(): SQL error: [Microsoft][ODBC Driver Manager]
Der Datenquellenname wurde nicht gefunden, und es wurde kein Standardtreiber angegeben,
SQL state IM002 in SQLConnect in C:\wamp\www\Concepts\index.php on line
Connection could not be established.
(翻译)
The Data Source could not be found, and no default driver is given.
这告诉我第一次执行能够找到数据库,但是没有打开它……为什么?
This tells me that the first execution was able to find the db, but did not open it... Why?
这是另一种配置吗?是否正在尝试执行客户端?我该怎么办?
Is this another config thing? Is it trying to execute Client-Side? What can I do?
答
您必须指定主机和连接协议:
You have to specify the Host and Connect protocol:
$connect_string = "Driver={SQL Anywhere 12};".
"CommLinks=tcpip(Host=$db_host);".
"ServerName=$db_server_name;".
"DatabaseName=$db_name;";
// Connect to DB
$conn = odbc_connect( $connect_string, $db_user, $db_pass );