How to convert mysql to mysqli?

后端 未结 3 1493
我寻月下人不归
我寻月下人不归 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条回答
  •  -上瘾入骨i
    2021-01-29 13:06

    In mysql, we used mysql_real_escape_string because you couldn't prepare statement.

    Now with mysqli, you have the ability to prepare statements which is the preferred way.

    connect_errno) {
        echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") ";
    }
    
    $query = "SELECT * FROM searchengine WHERE pagecontent LIKE ? LIMIT 0,?";
    $stmt = $mysqli->prepare($query);
    
    if (!$stmt) {
        echo "Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error;
    }
    $term = '%'.$_GET['term'].'%';
    $result = $_GET['results'];
    
    $stmt->bind_param("si", $term, $result);
    
    $stmt->execute();
    
    while ($ser = $stmt->fetch_assoc()) {
        echo "

    ".$ser['pageurl']."

    "; } $mysqli->close(); ?>

提交回复
热议问题