一个很基础的问题,但是在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
先附上源代码<?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
解决方案 »
- 我是新手,想学PHP
- 我被逼害了
- APACHE里 INDEX OF 界面 如何改变界面颜色
- PHP大问题!!!感激1万辈子
- $_key{0} != '_' && $$_key = my_addslashes($_value); 这是什么意思 ?
- 取出某列的值(连接mysql类的操作)
- 连接不了mysql,怎么回事???
- PHP和ASP。NET的比较?
- 這樣認為對不對???表中有表,在使用 width 時,外層的用數字,內層可用數字和百分數,但外層用百分數內層就不能用數字.
- 求问一下 我用 POST 传文件 $_FILES 打印出来是如上
- upload大文件 客户端
- .htaccess使浏览器打不开
表示 $result 不是 mysqli_result 对象,也就是说你的查询出了问题
$query = 'SELECT sku, name, price FROM proudcts ORDER by name';,,product拼错吧???
语句也没问题。前面我安装了Apache,MySQL,php的独立安装包,MySQL无法正常启动,后来就改成xampp了,根据网页的测试语句,能连接数据库,但是查询时出现了问题,仍旧很迷惑啊