How to convert mysql to mysqli?

后端 未结 3 1494
我寻月下人不归
我寻月下人不归 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 13:09

    Try using OOP style instead of procedural, it is much cleaner and more readable:

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

    May I also suggest you read some articles about how to use mysqli and preparted statements, instead of just hacking away and not reading the documentation. Using prepared statements removes the need for sprintf. Here are some useful links:

    PHP Website - http://www.php.net/manual/en/book.mysqli.php

    An article I found on google in about 5 seconds and looks quite good -http://mattbango.com/notebook/code/prepared-statements-in-php-and-mysqli/

提交回复
热议问题