sqlsrv_query函数不能执行sql代码,,但是把这段sql语句直接在sql server里面就能执行。。为什么
$tsql = "insert into BOOK( [ISBN], [shuming], [zuozhe], [chubanshe], [jiage], [fubenliang], [kucunliang] ) values( \'".$ISBN."\', \'".$shuming."\', \'".$zuozhe."\', \'".$chubanshe."\', ".$jiage.", ".$fubenliang.", ".$kucunliang." )";
$stmt = sqlsrv_query( $conn, $tsql );
$stmt一直是false
sqlsrv_query函数执行之前是需要连接SQLserver数据库的,也就是:
$serverName = "serverName\sqlexpress" ; //serverName\instanceName$connectionInfo = array( "Database" => "dbName" , "UID" => "userName" , "PWD" => "password" );
$conn = sqlsrv_connect ( $serverName , $connectionInfo );
if( $conn ) {
echo "Connection established.<br />" ;
}else{
echo "Connection could not be established.<br />" ;
die( print_r ( sqlsrv_errors (), true ));
}
能连上数据库,你再执行具体的SQL语句,如果还是false,可以输出sqlsrv_errors ()这个函数的结果看下是什么问题导致。
温馨提示:答案为网友推荐,仅供参考