PHP查询数据库数据时出现异常
程序员文章站
2022-06-05 16:13:25
...
PHP查询数据库数据时出现错误
PHP 查询数据库books中的books表时出现以下错误!
Notice: Trying to get property of non-object in D:\wamp\Apache\htdocs\php\results.php on line 33
Fatal error: Call to a member function fetch_assoc() on a non-object in D:\wamp\Apache\htdocs\php\results.php on line 35
代码如下:
上述问题那微微大虾能给个解决方案!
------解决方案--------------------
PHP 查询数据库books中的books表时出现以下错误!
Notice: Trying to get property of non-object in D:\wamp\Apache\htdocs\php\results.php on line 33
Fatal error: Call to a member function fetch_assoc() on a non-object in D:\wamp\Apache\htdocs\php\results.php on line 35
代码如下:
- PHP code
Book-O-Rama Catalog Search Book-O-Rama Catalog Search
query($sql); $num_result=$result->num_rows; for ($i=0;$ifetch_assoc(); echo "".($i+1)."title:"; echo htmlspecialchars(stripslashes($row['author'])); echo "Author:".stripslashes($row->newsauthor); echo "ISBN:".stripslashes($row->newsISBN); echo "price:".stripslashes($row->newsprice)."
"; } } $result->free(); $db->colse();?>
上述问题那微微大虾能给个解决方案!
------解决方案--------------------
- PHP code
$sql ="select * from books where ".$searchtype." like '%".$searchterm."%'"; if ($result=$db->query($sql)) { $num_result=$result->num_rows; for ($i=0;$ifetch_assoc(); echo "".($i+1)."title:"; echo htmlspecialchars(stripslashes($row['author'])); echo "Author:".stripslashes($row->newsauthor); echo "ISBN:".stripslashes($row->newsISBN); echo "price:".stripslashes($row->newsprice)."
"; } }else{ echo "fail."; exit; }相关文章
相关视频
推荐阅读
-
PHP实现获取并生成数据库字典的方法
-
mysql查询字符串替换语句小结(数据库字符串替换)
-
NaviCat连接时提示"不支持远程连接的MySql数据库"解决方法
-
Java连接mysql数据库并进行内容查询的方法
-
完美解决因数据库一次查询数据量过大导致的内存溢出问题
-
php mysql访问数据库的步骤详解
-
c#数据绑定之向查询中添加参数(.Net连接外部数据库)
-
Mysql数据库中子查询的使用
-
使用JDBC从数据库中查询数据的方法
-
Myeclipse链接Oracle等数据库时lo exception: The Network Adapter could not establish the connection