This question already has answers here:
Mysqli_Query warning: mysqli_query() expects parameter 1 to be mysqli [duplicate]
                                
                                    (2个答案)
                                
                        
                                4年前关闭。
            
                    
有人可以向我解释,并协助将我的旧代码转换为新的MySQLi格式吗?我将不胜感激。

这是我当前的代码:

<html>
    <head>
        <title>Last 10 Results</title>
    </head>
    <body>
        <table>
        <thead>
            <tr>
                <td>Id</td>
                <td>Name</td>
            </tr>
        </thead>
        <tbody>
        <?php
            $connect = mysql_connect("localhost","root", "root");
            if (!$connect) {
                die(mysql_error());
            }
            mysql_select_db("apploymentdevs");
            $results = mysql_query("SELECT * FROM demo LIMIT 10 ORDER BY Id");
            while($row = mysql_fetch_array($results)) {
            ?>
                <tr>
                    <td><?php echo $row['Id']?></td>
                    <td><?php echo $row['Name']?></td>
                </tr>

            <?php
            }
            ?>
            </tbody>
            </table>
    </body>
</html>


我再次感谢您的协助。

这就是我所做的(很抱歉,我是这样的菜鸟)

                    <?php
                        // Database details
                        $dbhost = 'localhost';
                        $dbuser = '#';
                        $dbpass = '#';
                        $dbname = '#';
                        $db = new mysqli($dbhost, $dbuser, $dbpass, $dbname);
                        if($db->connect_errno > 0){
                            die('Unable to connect to database [' . $db->connect_error . ']');
                        }
                        $results = mysqli_query("SELECT * FROM formdata LIMIT 10 ORDER BY id");
                        while($row = mysqli_fetch_array($results)) {
                        ?>
                            <tr>
                                <td><?php echo $row['ID']?></td>
                                <td><?php echo $row['FullName']?></td>
                                <td><?php echo $row['Mobile']?></td>
                                <td><?php echo $row['Email']?></td>
                                <td><?php echo $row['Province']?></td>
                            </tr>

                        <?php
                        }
                        ?>

最佳答案

更新此行:

$results = mysqli_query("SELECT * FROM formdata LIMIT 10 ORDER BY id");




$results = mysqli_query($db, "SELECT * FROM formdata ORDER BY id LIMIT 10");

关于php - 请帮助我将MySQL转换为MySQLi ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/32610586/

10-11 23:30
查看更多