一个很基础的问题,但是在Google上搜了N多帖子都没有解决
先附上源代码<?php
$mysqli = new MySQLi('localhost', 'root', '********', 'corporate');
/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s<br />", mysqli_connect_error());
    exit();
}else{
printf("connected successfully<br />");
}
//create the quary
$query = 'SELECT sku, name, price FROM proudcts ORDER by name';
//send query to mysql
printf("send query to mysql<br />");
$result = $mysqli->query($query, MYSQLI_STORE_RESULT);
//iterate through the result set
printf("iterate through the result set<br />");
while(list($sku, $name, $price) =$result->fetch_row()){
printf("(%s) $s: \$%s <br />", $sku, $name, $price);
}
?>数据库内容为:问题出现在  $result->fetch_row()这一行,使用 mysql_fetch_row()报出同样的错误。代码是从Apress出版社的《beginning PHP and mysql(the 4th edition)》这本书上拷过来的,页码是 595页。程序运行环境是 Windows 8, xampp 1.8。实在搞不懂是服务器配置的问题,还是代码的问题,求帮忙
mysqlphpquery

解决方案 »

  1.   

    出现 Call to a member function mysql_fetch_row() on a non-object ...
    表示 $result 不是 mysqli_result 对象,也就是说你的查询出了问题
      

  2.   

    这个问题一般就是SQL语句问题
    $query = 'SELECT sku, name, price FROM proudcts ORDER by name';,,product拼错吧???
      

  3.   


    语句也没问题。前面我安装了Apache,MySQL,php的独立安装包,MySQL无法正常启动,后来就改成xampp了,根据网页的测试语句,能连接数据库,但是查询时出现了问题,仍旧很迷惑啊
      

  4.   

    products确实没拼错,数据也没问题;把 corporate  换成 自带的数据库 mysql ,查询语句换成$query = 'SELECT host, user, password FROM user ORDER by host';其它也做对应修改,浏览器返回同样的错误。真心不明白问题出在了哪里