php错误提示: mysql_fetch_row(): supplied argument is not a valid MySQL
程序员文章站
2022-06-14 14:49:53
...
今天测试数据库连接,遍历数据表的中信息的是一直出现以下的错误:
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in D:\AppServ\www\wordpress\lianjie001.php on line 20
我原来写的代码是这样的:
$db_host="localhost";
$db_database="wordpress";
$db_username="root";
$db_password="admin123";
$connection=mysql_connect($db_host,$db_username,$db_password);
mysql_query("set names 'utf8'");
$sql="select * from huanzhexinxi";
$result=mysql_query($sql);
while($resultrowzhen=mysql_fetch_row(($result))){
$huanname=$resultrowzhen[0];
$huanage=$resultrowzhen[1];
$huancall=$resultrowzhen[2];
$huanliu=$resultrowzhen[3];
echo "";
echo "名字:$huanname ";
echo "年龄:$huanage ";
echo "电话:$huancall ";
echo "患者留言:$huanliu ";
echo "";
}
mysql_close($connection);
?>
检查半天也没有发现错误,后来经同事指点是缺少了选择数据库的代码如下所示:
$db_selecct=mysql_select_db($db_database);
完整的代码就是下面这样即可完成遍历。
$db_host="localhost";
$db_database="wordpress";
$db_username="root";
$db_password="admin123";
$connection=mysql_connect($db_host,$db_username,$db_password);
mysql_query("set names 'utf8'");
$db_selecct=mysql_select_db($db_database);
$sql="select * from huanzhexinxi";
$result=mysql_query($sql);
while($resultrowzhen=mysql_fetch_row(($result))){
$huanname=$resultrowzhen[0];
$huanage=$resultrowzhen[1];
$huancall=$resultrowzhen[2];
$huanliu=$resultrowzhen[3];
echo "
";
echo "名字:$huanname ";
echo "年龄:$huanage ";
echo "电话:$huancall ";
echo "患者留言:$huanliu ";
echo "";
}
mysql_close($connection);
?>
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resource in D:\AppServ\www\wordpress\lianjie001.php on line 20
我原来写的代码是这样的:
$db_host="localhost";
$db_database="wordpress";
$db_username="root";
$db_password="admin123";
$connection=mysql_connect($db_host,$db_username,$db_password);
mysql_query("set names 'utf8'");
$sql="select * from huanzhexinxi";
$result=mysql_query($sql);
while($resultrowzhen=mysql_fetch_row(($result))){
$huanname=$resultrowzhen[0];
$huanage=$resultrowzhen[1];
$huancall=$resultrowzhen[2];
$huanliu=$resultrowzhen[3];
echo "
echo "
echo "
echo "
echo "
echo "";
}
mysql_close($connection);
?>
检查半天也没有发现错误,后来经同事指点是缺少了选择数据库的代码如下所示:
$db_selecct=mysql_select_db($db_database);
完整的代码就是下面这样即可完成遍历。
$db_host="localhost";
$db_database="wordpress";
$db_username="root";
$db_password="admin123";
$connection=mysql_connect($db_host,$db_username,$db_password);
mysql_query("set names 'utf8'");
$db_selecct=mysql_select_db($db_database);
$sql="select * from huanzhexinxi";
$result=mysql_query($sql);
while($resultrowzhen=mysql_fetch_row(($result))){
$huanname=$resultrowzhen[0];
$huanage=$resultrowzhen[1];
$huancall=$resultrowzhen[2];
$huanliu=$resultrowzhen[3];
echo "
echo "
echo "
echo "
echo "
echo "";
}
mysql_close($connection);
?>
回复讨论(解决方案)
这到底是来提问的呢?还是来分享经验的呢?
结贴率为0,估计是一时心血来潮过来玩玩的吧
授人以鱼不如授人以渔
echo mysql_error();
mysql_query($sql) or die(mysql_error());
4楼正解.........
声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。
相关文章
相关视频
- 教你使用PHP数据库迁移工具“Phinx”
- 详解win10下PHP的安装配置(以php5.6为...
- php Swoole实现毫秒定时计划任务(详解)
- CodeIgniter基本配置详细介绍_PHP
- php错误提示: mysql_fetch_row(...
专题推荐
-
独孤九贱-php全栈开发教程
全栈 170W+
主讲:Peter-Zhu 轻松幽默、简短易学,非常适合PHP学习入门
-
玉女心经-web前端开发教程
入门 80W+
主讲:灭绝师太 由浅入深、明快简洁,非常适合前端学习入门
-
天龙八部-实战开发教程
实战 120W+
主讲:西门大官人 思路清晰、严谨规范,适合有一定web编程基础学习
- 最新文章
- 热门排行
推荐阅读
-
php错误提示: mysql_fetch_row(): supplied argument is not a valid MySQL
-
mysql_fetch_row(): supplied argument is not a valid MySQL result resource,何人能解?该如何解决
-
php出现Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result解决办法
-
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resour,该怎么解决
-
php出现Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result解决办法
-
php下foreach()错误提示Warning: Invalid argument supplied for foreach()
-
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resour,该怎么解决
-
求救:mysql_fetch_row(): supplied argument is not a valid MySQL result resource
-
【进去请严肃】从mysql取数据时提示Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result
-
Warning: mysql_fetch_row(): supplied argument is not a valid MySQL result resour,该怎么解决
网友评论
文明上网理性发言,请遵守 新闻评论服务协议
我要评论