IIS环境下PHP版本过低无法Sql查询的解决
2019-11-04 15:03:00 浏览:1668 作者:管理员
需求:帝国后台添加个后台框,输入地址,原页面重写成所指链接页面
重点:当输入框输入地址,提交到后台后,打开原链接,该页面会读取php文件GetUrlPage.php
1 <?php 2 header("Content-Type: text/html;charset=utf-8"); 3 $str=''; 4 $result['status']=1; 5 $id = $_POST["id"]; 6 $con=mysqli_connect("localhost","root","root","ce"); 7 if(mysqli_connect_errno($con)){ 8 echo "连接 MySQL 失败:".mysqli_connect_error(); 9 }10 $sql="SELECT change_url FROM phome_ecms_download where id=".$id;11 $row=mysqli_query($con,$sql);12 if($row['change_url']){13 $str=getHttps($row['change_url']);14 }15 if($str){16 $result['status']=2;17 $result['info']=$str;18 }19 //获取外链页面20 function getHttps($url){ 21 //初始化22 $ch = curl_init();23 //设置选项,包括URL24 curl_setopt($ch, CURLOPT_URL, $url);25 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);26 curl_setopt($ch, CURLOPT_HEADER, 0);27 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // https请求 不验证证书和hosts28 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);29 30 $output = curl_exec($ch); //执行并获取HTML文档内容31 $str = $output;//转换为源代码形式32 //释放curl句柄33 curl_close($ch);34 return $str ;35 }36 37 echo json_encode($result);38 ?>
根据排错,发现 $sql 无法输出相应的值,换做低版本写法:
1 <?php 2 header("Content-Type: text/html;charset=utf-8"); 3 $str=''; 4 $result['status']=1; 5 $id = $_POST["id"]; 6 $conn=@mysql_connect("localhost","root","root","ce") or die('服务器连接失败'.mysql_error()); 7 @mysql_select_db('phome') or die('数据库连接错误'.mysql_error()); 8 mysql_query("set names 'utf8'"); 9 $sql ="SELECT change_url FROM phome_ecms_download where id=".$id; 10 $query=mysql_query($sql); 11 $row=mysql_fetch_array($query,MYSQL_ASSOC); 12 if($row['change_url']){ 13 $str=getHttps($row['change_url']); 14 } 15 if($str){ 16 $result['status']=2; 17 $result['info']=$str; 18 } 19 //获取外链页面 20 function getHttps($url){ 21 //初始化 22 $ch = curl_init(); 23 //设置选项,包括URL 24 curl_setopt($ch, CURLOPT_URL, $url); 25 curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 26 curl_setopt($ch, CURLOPT_HEADER, 0); 27 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // https请求 不验证证书和hosts 28 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); 29 30 $output = curl_exec($ch); //执行并获取HTML文档内容 31 $str = $output;//转换为源代码形式 32 //释放curl句柄 33 curl_close($ch); 34 return $str ; 35 } 36 37 echo json_encode($result); 38 ?>
经测试OK!!!
结论:PHP版本低于程序语句标准,Sql语句不起作用!