依照韩顺平老师写的!出错了!Fatal error: Call to a member function query() on a non-object in
Fatalerror:Calltoundefinedmethodmysqli_tools::mysqli_query()inE:\AppServ\www\mysql\my...
Fatal error: Call to undefined method mysqli_tools::mysqli_query() in E:\AppServ\www\mysql\mysqli_tools.php on line 16
好可恶,真心看不出哪里错了!大家帮帮忙,好人有好报!!
<?php
class mysqli_tools{
private $mysqli;
public function tools(){
$this->mysqli=new MYSQLi("127.0.0.1","root","root","user");
if($this->mysqli->connect_error){
die("连接出错".$this->mysqli->connect_error);
}
$this->mysqli->query("set names gbk");
}
public function execute_dql($sql){
$res=$this->mysqli_query($sql) or die ("操作失败".$this->mysqli->error);
return $res;
}
//这就是出错的那行!
public function execute_dml($sql){
$res=$this->mysqli_query($sql);
if(!$res){
return 0;
}else{
if($this->mysqli->affected_rows>0){
return 1;
}
else{
return 2;
}
}
}
}
?>
<?php
require "mysqli_tools.php";
$mst=new mysqli_tools();
$sqls="insert into words(enword,chword) values('mousea','老鼠了,耗子了')";
//$sql="select * from words";
$res=$mst->execute_dml($sqls);
if($res==0){
echo "操作失败";
}
else{
if($res==1){
echo "操作成功";
}else {
echo "没有影响";
}
}
?> 展开
好可恶,真心看不出哪里错了!大家帮帮忙,好人有好报!!
<?php
class mysqli_tools{
private $mysqli;
public function tools(){
$this->mysqli=new MYSQLi("127.0.0.1","root","root","user");
if($this->mysqli->connect_error){
die("连接出错".$this->mysqli->connect_error);
}
$this->mysqli->query("set names gbk");
}
public function execute_dql($sql){
$res=$this->mysqli_query($sql) or die ("操作失败".$this->mysqli->error);
return $res;
}
//这就是出错的那行!
public function execute_dml($sql){
$res=$this->mysqli_query($sql);
if(!$res){
return 0;
}else{
if($this->mysqli->affected_rows>0){
return 1;
}
else{
return 2;
}
}
}
}
?>
<?php
require "mysqli_tools.php";
$mst=new mysqli_tools();
$sqls="insert into words(enword,chword) values('mousea','老鼠了,耗子了')";
//$sql="select * from words";
$res=$mst->execute_dml($sqls);
if($res==0){
echo "操作失败";
}
else{
if($res==1){
echo "操作成功";
}else {
echo "没有影响";
}
}
?> 展开
展开全部
$res=$this->mysqli_query($sql);改成
$res=$this->mysqli->query($sql);
$res=$this->mysqli->query($sql);
追问
改了,不过还是错!还是那行出错
Fatal error: Call to a member function query() on a non-object in E:\AppServ\www\mysql\mysqli_tools.php on line 16
追答
工具类实例化以后你要调用里面的tools方法连接数据库:$mst->tools();
另外有两个地方你都成了mysqli_query。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
2013-12-18
展开全部
单词拼写错误 mysql_query 你都写的mysqli_query
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询