php 一个类调用另一个类的方法
<?phprequire_once("conn/conn.php");$db=newdb("localhost","root","123456","blog");$db-...
<?php
require_once("conn/conn.php");
$db=new db("localhost","root","123456","blog");
$db->connec();
class Login{
public $name;
public $password;
function sql($name,$password){
$this->name=$name;
$this->password=$password;
$sql="select * from user where name='$name' and password='$password'";
$db->execute($sql);
}
}
?>
db是conn.php中的类里面有executed等方法,我想调用可是
出现一下提示:
Call to a member function execute() on a non-object in D:\AppServ\www\oopLogin\login.php on line 18
怎么改呀, 展开
require_once("conn/conn.php");
$db=new db("localhost","root","123456","blog");
$db->connec();
class Login{
public $name;
public $password;
function sql($name,$password){
$this->name=$name;
$this->password=$password;
$sql="select * from user where name='$name' and password='$password'";
$db->execute($sql);
}
}
?>
db是conn.php中的类里面有executed等方法,我想调用可是
出现一下提示:
Call to a member function execute() on a non-object in D:\AppServ\www\oopLogin\login.php on line 18
怎么改呀, 展开
4个回答
展开全部
一种是将你的变量写成
global $db
第二种是,将$db=new db("localhost","root","123456","blog");
$db->connec();
放在你的类中。
global $db
第二种是,将$db=new db("localhost","root","123456","blog");
$db->connec();
放在你的类中。
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
$db调用了类以后的变量
可将
$db=new db("localhost","root","123456","blog");
$db->connec();
放在 function sql()方法里面
可将
$db=new db("localhost","root","123456","blog");
$db->connec();
放在 function sql()方法里面
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
<?php
require_once("conn/conn.php");
class Login{
public $name;
public $password;
function sql($name,$password){
$db=new db("localhost","root","123456","blog");
$db->connec();
$this->name=$name;
$this->password=$password;
$sql="select * from user where name='$name' and password='$password'";
$db->execute($sql);
}
}
?>
require_once("conn/conn.php");
class Login{
public $name;
public $password;
function sql($name,$password){
$db=new db("localhost","root","123456","blog");
$db->connec();
$this->name=$name;
$this->password=$password;
$sql="select * from user where name='$name' and password='$password'";
$db->execute($sql);
}
}
?>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
$db->connec();
这句写错了。
应为:$db->connect();
这句写错了。
应为:$db->connect();
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询