测试代码:
<html> <head> <title>通过PHP连接MySQL服务器</title> </head> <body> <?php $link = mysqli_connect("127.0.0.1", "root", "123456", "bishe"); if (!$link) { echo "Error: Unable to connect to MySQL." . PHP_EOL; echo "Debugging errno: " . mysqli_connect_errno() . PHP_EOL; echo "Debugging error: " . mysqli_connect_error() . PHP_EOL; exit; } $sql = "SELECT * FROM choice_error"; $result = $link->query($sql); if ($result->num_rows > 0) { // 输出数据 while($row = $result->fetch_assoc()) { echo "id: " . $row["question_id"]. " - Name: " . $row["question_name"]. " " . $row["question_type"]. "" ""; } } else { echo "0 结果"; } echo "Success: A proper connection to MySQL was made! The my_db database is great." . PHP_EOL; echo "Host information: " . mysqli_get_host_info($link) . PHP_EOL; mysqli_close($link); ?> </body> </html>