سلام
این دو تا کلاس رو ببینید و بگید این اررور از چیه؟
این تو یه فایل database.php
اینم تو یه فایل به اسم dbtools.php
اینم خطایی که میگیره
لطفا راهنمایی کنید
این دو تا کلاس رو ببینید و بگید این اررور از چیه؟
این تو یه فایل database.php
PHP:
<?
class database{
private $resource;
private $result;
function database(){
if(function_exists("mysql_connect"))
{
if($this->resource=mysql_connect("localhost","root","2363"))
mysql_select_db("oop",$this->resource);
}
}
function query($sql){
if($sql !="")
$this->result=mysql_query($sql,$this->resource);
}
function res1(){
if($this->result)
{
while($row=mysql_fetch_row($this->result))
$r[]=$row;
}
mysql_free_result($this->result);
return $r;
}
//get_num_row
function get_num(){
if($this->result)
return mysql_num_rows($this->result);
} // End function
//last_insert_id
function last_id(){
if($this->result)
return mysql_insert_id($this->result);
} // End function
//First Field
function field($key=0){
if($this->result) {
$row=mysql_fetch_array($this->result);
return $row[$key] ;
}
} // End function
}
?>
اینم تو یه فایل به اسم dbtools.php
PHP:
<?
require 'dataBase.php';
class dbtools{
protected $db;
protected $table;
function dbtools($db,$table){
$this->db=$db;
$this->table=$table;
}
function add($arr){
if(count($arr)>0) {
$sql="insert into `%s` (%s) values (%s)";
foreach($arr as $k=>$v) {
if($v=='') continue;
$tmp_k[] = $k;
$tmp_v[] = ($k=='password') ? 'MD5('.$v.')' : "'". mysql_escape_string($v) ."'";
}
$sql = sprintf($sql, $this->table, implode(',',$tmp_k), implode(',', $tmp_v));
$sql = printf($sql, $this->table, implode(',',$tmp_k), implode(',', $tmp_v));
$this->db->query($sql);
}
}
function update($arr,$id){
if(count($arr)>0) {
$sql="update `%s` set %s where id='%d'";
foreach($arr as $k=>$v) {
if($v=='') continue;
$v = ($k='password') ? 'MD5('.$v.')' : "'". mysql_escape_string($v) ."'";
$tot[] = $k."=".$v;
}
$sql = sprintf($sql, $this->table, implode(',',$tot),$id);
$this->db->query($sql);
}
}
}
$db=new database() ;
$user=new dbtools('oop','test');
$sql=array('email'=>'[email protected]','name'=>'Naser','age'=>25);
$user->add($sql);
?>
اینم خطایی که میگیره
کد:
Fatal error: Call to a member function query() on a non-object in D:\wwwroot\oop\dbtools.php on line 23
لطفا راهنمایی کنید