WAMP php ODBC Connection'警告'

时间:2015-08-27 11:31:11

标签: php odbc wamp sqlanywhere

我在php中遇到ODBC问题(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"然后我明白了:

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.

这告诉我第一次执行能够找到db,但是没有打开它......为什么?

这是另一个配置吗?它是否尝试执行客户端?我该怎么办?

1 个答案:

答案 0 :(得分:0)

您必须指定主机和连接协议:

$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 );