doutou7961 2016-01-11 17:18
浏览 32

PHP,sqlsrv连接无法正常工作

hi am trying to connect to sql server through php, search and display the results based on search string. following is the index.php

am successful in getting the results separately by writing query but not through this search form

Following is the 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);
}
}
?>
  • 写回答

1条回答 默认 最新

  • dtutlamjasblef7982 2016-02-12 11:44
    关注

    use

    This for mysqli connection

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

    This for mysql connection

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

报告相同问题?

悬赏问题

  • ¥15 基于单片机的靶位控制系统
  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错