MSQL到MYSQLI转换器

时间:2015-07-08 20:22:56

标签: php mysql mysqli

我不熟悉MySQLi

<?php
    $bestaat = mysql_query("SELECT * FROM badgesdownload LIMIT 7");  
    while($bestaat2 = mysql_fetch_array($bestaat)) {
        $bestaat3 = $bestaat2['naam'];
        $txt = mysql_query("SELECT * FROM badgesdownload WHERE naam = '".$bestaat3."'"); 
        while($txt2 = mysql_fetch_array($txt)){
            $txt3 = $txt2['txt'];   
            echo $bestaat3; 
            echo'<br>';
            echo $txt3;
            echo'<br>';
        }
    }
?>

如何将此脚本更改为mysqli?

1 个答案:

答案 0 :(得分:0)

Mysqli - 程序方法非常相似。只需将数据库连接添加为查询的第一个参数,并在所有函数中添加“i”...

$bestaat = mysqli_query($db, "SELECT * FROM badgesdownload LIMIT 7");

while($bestaat2 = mysqli_fetch_array($bestaat)) {
    $bestaat3 = $bestaat2['naam'];
    $txt = mysqli_query($db, "SELECT * FROM badgesdownload WHERE naam = '$bestaat3'");
    while($txt2 = mysqli_fetch_array($txt)){              
        echo $bestaat3.'<br>'.$txt2['txt'].'<br>';
    }
}

我还修正了一些明显的错误.. ..关闭括号是主要的。