php连接sql serve后如何执行sql语句
Posted 野望之风
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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语句的主要内容,如果未能解决你的问题,请参考以下文章
SQL语句报错:You have an error in your SQL syntax; check the manual that corresponds to your MariaDB serv