The php project server shows that mysql_connect has been abandoned?

when a rookie at the front end is working on a small project

<?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");//utf8utf8--

$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;$jPP){
    $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:
                -sharp 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);

the local server environment can be accessed normally, but as soon as it is placed on the network server, it will report an error mysql_connect
. After looking it up on the Internet, it is said that mysql_connect has been abandoned, but I changed it myself or asked my seniors to help me or thank you for the above php code

.

online PHP version is too high

PHP5.5 is prompted as a method to be deleted at the beginning, and has been completely removed since 7. 0. Please keep up with the release progress of PHP

it's not that the online php version is too high, but that your local php version is too low
Don't use mysql_connect or mysqli, use pdo, or directly use the tp3 framework


Install the mysqli extension on the

server and replace all the mysql_* functions with mysqli_ .

http://php.net/manual/zh/mysqli.installation.php


  1. if you need to use the mysql_connect function, it is recommended that PHP version 5.3
  2. it is recommended to use PDO to operate the database. The full version supports

read more documents

clipboard.png


the tutorials you read are too old. 4 when you were young, many people didn't use mysql series functions when they first learned PHP.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1bddc3d-3974f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1bddc3d-3974f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?