首页 > 代码库 > php连接sql serve后如何执行sql语句

php连接sql serve后如何执行sql语句

<?php
header("Content-type:text/html;charset=utf-8");
//
$conInfo=array(‘Database‘=>‘dbname‘, ‘UID‘=>‘user‘, ‘PWD‘=>‘password‘);

$conn=sqlsrv_connect(‘servername/IP‘, $conInfo);

$sql = "SELECT * FROM Product where ProductNo=10001";

$params = array();

$options = array( "Scrollable" => SQLSRV_CURSOR_KEYSET );

$stmt = sqlsrv_query($conn, $sql , $params, $options );

$row_count = sqlsrv_num_rows( $stmt );

/*判断连接成功与否:*/

if(!$conn) echo "FAILD!连接错误,用户名密码不对";
else echo "OK!可以连接";

//判断查询结果的行数
if ($row_count === false)
echo "Error in retrieveing row count.";
else
echo $row_count;

?>

php连接sql serve后如何执行sql语句