我有以下代码从数据库检索信息。它通过连接连接到数据库,但是当我尝试显示信息时,我什么也看不到。我只会
虚线。我认为问题出在while循环中,我只是看不到我的错误在哪里。谁能帮忙?

 $connection = mysql_connect("127.0.0.1","root","xxxxxxxx");
        if (!$connection)
        {
        printf("Can't connect to MySQL Server.", mysqli_connect_error());

        }


    mysql_select_db('xxxxxx') or die ('Could not select database');
        echo 'You have been connected succesfully to your database';

        $query = "SELECT *FROM testing";
        $result = mysql_query($query) or die("Query fail:".mysql_error());


        while ($row = mysql_fetch_array($result));
        {
            echo $row['age']."--".$row['sex']."--".$row['id']."--".$row['country']."--".$row['sport']." ";
        }

        ?>

最佳答案

使用mysqli

$db = new mysqli("localhost","admin","XXXXXX","test");
if($db->connect_errno > 0){
    die('Unable to connect to database [' . $db->connect_error . ']');
}

$query = "SELECT * FROM `testing`";

if(!$result = $db->query($query)){
    die('There was an error running the query [' . $db->error . ']');
}

// echo $result->num_rows;  Uncomment to make sure there is data being ruturned

while($row = $result->fetch_assoc()){
    echo $row['age']."--".$row['sex']."--".$row['id']."--".$row['country']."--".$row['sport']." ";
}

10-07 14:20
查看更多