显示数据库中的数据

时间:2013-06-10 04:50:55

标签: php sql

我正在尝试这个基于Web的字典进行学习,但是我在从数据库中获取结果并显示单词时遇到了一些问题。它显示一条错误消息“mysql_fetch_row()期望参数1为资源,布尔值在第14行的C:\ wamp \ www \ Dictionary \ home.php中给出” 下面是代码..请帮助

<?php
$con=mysqli_connect("localhost","dictionary");

// Check connection
if (mysqli_connect_errno($con))
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
?>
<table>
<?php
$result=mysql_query("select word from word_table order by asc");
//$row = mysql_query($result);
while($word = mysql_fetch_row($result))
{
echo("<tr><td>$word[0]</td></tr>");
}
?>

1 个答案:

答案 0 :(得分:2)

您必须在此处使用mysqli,因为您使用了mysqli dor DB连接

$result=mysqli_query($con,"select word from word_table order by asc");

while($word = mysqli_fetch_row($result))

同样mysqli_connect需要4个参数进行数据库连接

$con=mysqli_connect("localhost","dictionary","your_password","db_name");

修改

$result=mysqli_query($con,"select word from word_table order by column_name asc");