IIS环境下PHP版本过低无法Sql查询的解决

需求:帝国后台添加个后台框,输入地址,原页面重写成所指链接页面

重点:当输入框输入地址,提交到后台后,打开原链接,该页面会读取php文件GetUrlPage.php

<?php 
header("Content-Type: text/html;charset=utf-8");
$str=‘‘;
$result[‘status‘]=1;
 $id = $_POST["id"];
$con=mysqli_connect("localhost","root","root","ce");
if(mysqli_connect_errno($con)){
    echo "连接 MySQL 失败:".mysqli_connect_error();
}
$sql="SELECT change_url FROM phome_ecms_download where id=".$id;
$row=mysqli_query($con,$sql);
if($row[‘change_url‘]){
    $str=getHttps($row[‘change_url‘]);
}
if($str){
    $result[‘status‘]=2;
    $result[‘info‘]=$str;
}
//获取外链页面
function getHttps($url){    
   //初始化
        $ch = curl_init();
        //设置选项,包括URL
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); // https请求 不验证证书和hosts
        curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
        
        $output = curl_exec($ch); //执行并获取HTML文档内容
        $str = $output;//转换为源代码形式
        //释放curl句柄
        curl_close($ch);
    return  $str ;
    }
    
echo json_encode($result);
?>

根据排错,发现 $sql 无法输出相应的值,换做低版本写法:

<?php 
    header("Content-Type: text/html;charset=utf-8");
    $str=‘‘;
    $result[‘status‘]=1;
    $id = $_POST["id"];
    $connmysql_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语句不起作用!