PHP,sqlsrv连接不工作


PHP , sqlsrv connection not working

hi-am试图通过php连接到sqlserver,根据搜索字符串搜索并显示结果。以下是index.php

我通过写查询成功地获得了单独的结果,但没有通过这个搜索表单

以下是search.php

  <?php
$button = $_GET ['submit'];
$search = $_GET ['search']; 
if(!$button)
echo "you didn't submit a keyword";
else
{
if(strlen($search)<=1)
echo "Search term too short";
else{
echo "You searched for <b>$search</b> <hr size='1'></br>";
}
$serverName = "xxxx";
$connectionInfo = array( "Database"=>"xxxx", "UID"=>"xxxx", "PWD"=>"xxxx");
$conn = sqlsrv_connect( $serverName, $connectionInfo );
$Query = "SELECT employee_name FROM employees WHERE employee_name like '%".$search."%'";
$run = sqlsrv_query($conn,$Query);

$foundnum = sqlsrv_num_rows($run);
if ($foundnum==0)
echo "Sorry, there are no matching result for <b>$search</b>.</br></br>1.";
else
{
echo "$foundnum results found !<p>";
while($row = SQLSRV_FETCH_ARRAY($run,SQLSRV_FETCH_ASSOC))
{
    echo $row['Employee_name'];
    }
sqlsrv_free_stmt($run);
}
}
?>

使用

这适用于mysqli连接

$con = mysqli_connect("localhost","my_user","my_password","my_db");

此用于mysql连接

$con = mysql_connect("localhost","my_user","my_password","my_db");