php 版本过低 怎么修改?
自己弄了个小项目 在本地localhost环境下没问题,但放到网络服务器就报错 ,网上查了下是 mysql_connect 已经被高版本php废弃了, 我只是个前端菜鸟 怎么改都报错 求前辈帮忙改一下 以下为项目包 sql文件也在里
https://pan.baidu.com/s/1e7Kx...
<?php
header("Content-type: text/html;charset=utf-8");//防止乱码
//1、获取链接
$conn=@mysql_connect("localhost","root","0123456zp");
if(!$conn){
//mysql_error()是返回mysql的上一次操作
die("连接失败".mysql_error());
}else{
//echo '连接成功!<br/>';
}
//2、选择对应的数据库
@mysql_select_db("caiwu");
//3、设置操作编码(可有可无,建议有)
mysql_query("set names utf8");//保证是按照utf8码操作的【utf8无-的,有-的是网页版的!!!!!!!】
$draw = $_GET['draw']; //第几次请求
//排序
$order_column = $_GET['order']['0']['column']; // 哪一列排序
$order_dir= $_GET['order']['0']['dir']; // ase desc 升序或者降序
//拼接排序sql
$orderSql = "";
if(isset($order_column)){
$i = intval($order_column);
switch($i){
case 0;$orderSql = " order by id ".$order_dir;break;
case 1;$orderSql = " order by kh ".$order_dir;break;
case 2;$orderSql = " order by kj ".$order_dir;break;
case 3;$orderSql = " order by cpx ".$order_dir;break;
case 4;$orderSql = " order by zhd ".$order_dir;break;
case 5;$orderSql = " order by afzhd ".$order_dir;break;
case 6;$orderSql = " order by afxjd ".$order_dir;break;
case 7;$orderSql = " order by zxrq ".$order_dir;break;
case 8;$orderSql = " order by xs ".$order_dir;break;
case 9;$orderSql = " order by crrq ".$order_dir;break;
case 10;$orderSql = " order by skr ".$order_dir;break;
case 11;$orderSql = " order by skzh ".$order_dir;break;
default;$orderSql = '';
}
}
//分页
$start = $_GET['start'];//从多少开始
$length = $_GET['length'];//数据长度
$limitSql = '';
$limitFlag = isset($_GET['start']) && $length != -1 ;
if ($limitFlag ) {
$limitSql = " LIMIT ".intval($start).", ".intval($length);
}
//定义查询数据总记录数sql
$sumSql = "SELECT count(id) as sum FROM financialdata";
//条件过滤后记录数 必要
$recordsFiltered = 0;
//表的总记录数 必要
$recordsTotal = 0;
$recordsTotalResult = mysql_query($sumSql,$conn);
while($row=mysql_fetch_assoc($recordsTotalResult)){
$recordsTotal = $row['sum'];
}
//搜索//定义过滤条件查询过滤后的记录数sql
$search = $_GET['search']['value'];//获取前台传过来的过滤条件
// 每列搜索
$j = 1;
$search_arr =array();
$colSearchSql='';
for($j=0;$j<6;$j++){
$colSearchable = $_GET['columns'][$j]['searchable'];
$colSearchVal = $_GET['columns'][$j]['search']['value'];
if(strlen($colSearchVal)>0 && $colSearchable == 'true' ){
switch ($j) {
case 0: $colSearchVal = "id LIKE '%".$colSearchVal."%'";
array_push($search_arr,$colSearchVal);
break;
case 1: $colSearchVal = "kh LIKE '%".$colSearchVal."%'";
array_push($search_arr,$colSearchVal);
break;
case 2: $colSearchVal = "kj LIKE '%".$colSearchVal."%'";
array_push($search_arr,$colSearchVal);
break;
case 3: $colSearchVal = "cpx LIKE '%".$colSearchVal."%'";
array_push($search_arr,$colSearchVal);
break;
case 4: $colSearchVal = "zhd LIKE '%".$colSearchVal."%'";
array_push($search_arr,$colSearchVal);
break;
case 5: $colSearchVal = "afzhd LIKE '%".$colSearchVal."%'";
array_push($search_arr,$colSearchVal);
break;
case 6: $colSearchVal = "afxjd LIKE '%".$colSearchVal."%'";
array_push($search_arr,$colSearchVal);
break;
case 7: $colSearchVal = "zxrq LIKE '%".$colSearchVal."%'";
array_push($search_arr,$colSearchVal);
break;
case 8: $colSearchVal = "xs LIKE '%".$colSearchVal."%'";
array_push($search_arr,$colSearchVal);
break;
case 9: $colSearchVal = "crrq LIKE '%".$colSearchVal."%'";
array_push($search_arr,$colSearchVal);
break;
case 10: $colSearchVal = "skr LIKE '%".$colSearchVal."%'";
array_push($search_arr,$colSearchVal);
break;
case 11: $colSearchVal = "skzh LIKE '%".$colSearchVal."%'";
array_push($search_arr,$colSearchVal);
break;
default:
# code...
break;
}
}
}
if(empty($search_arr) == false){
$colSearchSql = " WHERE ".implode(" AND ",$search_arr);
}
// 综合搜索sql
// $zSearchSql =" where teacher_id || teacher_name || teacher_password || teacher_email || teacher_date || teacher_note LIKE '%".$search."%'";
$zSearchSql = " id LIKE '%".$search."%' OR kh LIKE '%".$search."%' OR kj LIKE '%".$search."%' OR cpx LIKE '%".$search."%' OR zhd LIKE '%".$search."%' OR afzhd LIKE '%".$search."%'OR afxjd LIKE '%".$search."%'OR zxrq LIKE '%".$search."%'OR xs LIKE '%".$search."%'OR crrq LIKE '%".$search."%'OR skr LIKE '%".$search."%'OR skzh LIKE '%".$search."%'";
// 拼接搜索SQL
$sumSearchSql = '';
if(strlen($colSearchSql)>0 && strlen($search)>0){
$sumSearchSql = $colSearchSql." AND (".$zSearchSql.")";
}else if(strlen($colSearchSql)>0 && strlen($search)==0){
$sumSearchSql = $colSearchSql;
}else if(strlen($colSearchSql)==0 && strlen($search)>0){
$sumSearchSql = " WHERE ".$zSearchSql;
}else{
$sumSearchSql = '';
}
if(strlen($sumSearchSql)>0){
$recordsFilteredResult = mysql_query($sumSql.$sumSearchSql);
while ($row = mysql_fetch_assoc($recordsFilteredResult)) {
$recordsFiltered = $row['sum'];
}
}else{
$recordsFiltered = $recordsTotal;
}
// query data
$sql='';
$totalResultSql = "SELECT * FROM financialdata";
$infos = array();
// 拼接最终SQL
$sql=$totalResultSql.$sumSearchSql.$orderSql.$limitSql;
$dataResult = mysql_query($sql,$conn);
while ($row = mysql_fetch_assoc($dataResult)) {
// $obj = array($row['teacher_id'], $row['teacher_name'], $row['teacher_password'], $row['teacher_email'], $row['teacher_date'], $row['teacher_note']);
// array_push($infos,$obj);
array_push($infos,$row);
}
// return data
echo json_encode(array(
"draw" => $draw,
"recordsTotal" =>$recordsTotal, // necessary
"recordsFiltered" =>$recordsFiltered, // necessary
"data" =>$infos // necessary
),JSON_UNESCAPED_UNICODE);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
只是warning的话,可以设置
error_reporting(0);
来关闭界面的错误。或者 将所有的
mysql_connect()
切换为mysqli_connect()
。使用 mysqli
在服务器上重新装下低版本的php,或者可以的话,多装几个版本,想换的话直接切换。mysql_connect是要php5.5以下的版本。
现在mysql_connect只是即将被废弃了,并没有马上废弃啊。现在是可以用的,但是要尽量更换为mysqli
对的,基本上
mysql
换成mysqli
就好了看看框架里对mysql连接是怎么处理的,可以借鉴过来
ctrl+f 搜索
mysql
替换为mysqli