WAMP php ODBC Connection 'Warning'

巧了我就是萌 提交于 2019-12-11 13:44:16

问题


I have a problem with ODBC in php (WAMP Server 2.5, PHP 5.5.12).

When I try to run:

$conn = odbc_connect("odbc_dsn", "user", "pwd");

if ($conn) 
{
    echo "Connection established.";
} 
else
{
    exit("Connection could not be established.");
}

I get a Warning:

Warning: odbc_connect(): in C:\wamp\www\Concepts\index.php on line 29

Connection could not be established.

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.

(Translated)

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?


回答1:


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


来源:https://stackoverflow.com/questions/32248246/wamp-php-odbc-connection-warning

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!