How to convert mysql to mysqli?

后端 未结 3 1496
我寻月下人不归
我寻月下人不归 2021-01-29 12:50

I tired to convert my mysql to mysqli but seems to be getting a lot of errors and warnings i got no problem connecting to the data base but the rest of the code seems wrong what

3条回答
  •  礼貌的吻别
    2021-01-29 12:53

    you can try it by creating a mysqli object like described here: http://www.php.net/manual/en/class.mysqli.php

    or simply like this:

    $db = new mysqli($hostname, $username, $password, $database);

    and then query it like this:

    $result = $db->query('SQL HERE');

    in your case the code for mysqli would look like this

    $db = new mysqli("localhost","root","","searchengine");
    
    $result = $db->query(sprintf(
      "SELECT * FROM searchengine WHERE pagecontent LIKE '%s' LIMIT 0,%d",
      '%'. mysqli_real_escape_string($_GET['term']) .'%',
      $_GET['results'])
    );
    
    while($ser = mysqli_fetch_array($result)) {
        echo "

    $ser[pageurl]

    "; }

提交回复
热议问题