使用odbc连接问题的连接

时间:2012-12-13 11:25:00

标签: php sql odbc

我正在使用它来打印sql server中特定表的所有名称,这里是代码:

$host="";
$uid="";
$passVal="";
$database="montim";
odbc_connect("Driver={SQL Server};Server=$host;Database=$database;",$uid, $passVal ) or die("Connection could not established");
$query = "SELECT * FROM users";
$res = odbc_exec($query) or die(odbc_error());
while( $row = odbc_fetch_array($res) ) {
print_r($row); 
}

我想出了这个错误:

 Warning: odbc_exec() expects at least 2 parameters, 1 given in
有人可以帮助我,为什么会这样? 我的意思很简单,我不是想做一些复杂的事情...... 感谢

2 个答案:

答案 0 :(得分:2)

ODBC_EXEC还需要connection_id。尝试

$connection = odbc_connect("Driver={SQL Server};Server=$host;Database=$database;",$uid,    
...
$res = odbc_exec($connection, $query) or die(odbc_error());

答案 1 :(得分:0)

ODBC函数不会像mysql_函数那样隐式记住幕后的活动连接。这是一件好事,BTW。您需要跟踪连接并传递它:

$con = odbc_connect(...);
odbc_exec($con, ...);

请阅读手册并注意必要的参数:http://php.net/manual/en/function.odbc-exec.php