Home  >  Article  >  Backend Development  >  php7 cannot use mysql

php7 cannot use mysql

angryTom
angryTomOriginal
2019-10-31 13:58:524944browse

php7 cannot use mysql

php7 cannot use mysql

After many people upgrade from php5 to php7, the program cannot run normally, especially The mysql database cannot be connected. Let’s take a look at the solution.

After upgrading php7, I found that some projects that have been completed and placed locally cannot be used normally. This is because the functions of the mysql_ class have been abandoned by php7. In fact, As early as php5, the official has made it clear that this type of function will be abandoned. The following is a comparison of query data after php5 and php7 associate the database:

php5:
<?php
    header("content-type:text/html;charset=utf-8");
    error_reporting(E_ALL ^ E_DEPRECATED);
    $link = mysql_connect("127.0.0.1","root","123456");
    mysql_select_db("shunyi",$link);
    mysql_query("set names utf8");
    $point = "select * from sy_location";
    $rest = mysql_query($point);
    $arr = array();
    while($re = mysql_fetch_assoc($rest)){
        array_push($arr, $re);
    }
    echo json_encode($arr);
?>
php7:
<?php
    header("content-type:text/html;charset=utf-8");
    error_reporting(E_ALL ^ E_DEPRECATED);
    $link = mysqli_connect("127.0.0.1","root","123456","shunyi");
    $point = "select * from sy_location";
    $rest = mysqli_query($link,$point);
    $arr = array();
    while($re = mysqli_fetch_assoc($rest)){
        array_push($arr, $re);
    }
    echo json_encode($arr);
?>

For more PHP related knowledge, please visit PHP Chinese website !

The above is the detailed content of php7 cannot use mysql. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn