2014-12-21 88 views
-1

我很新的Postgresql.what是這個錯誤?php pg_query()不工作?

警告:pg_query()預計參數1是資源,在C空給出:\ XAMPP \ htdocs中\ torf.php上線25

class user { 

private $link=null; 

private function connect() { 
    if ($this->link == null || !pg_ping($this->link)) { 
     $this->link = pg_connect("host=localhost port=5432 dbname=bigchance user=postgres password=lamp"); 
    } 
} 

public function user() { 
    $this->connect(); 
} 

public function new_id() { 
    $id=0; 
    $result = pg_query (user::connect(), "select * from user order by id desc limit 1 "); 
    if ($result != false && pg_num_rows($result>0)) { 
     $id= pg_fetch_result($result,0,0); 
    } 
    $id++; 
    return $id; 
} 

public function insert($email,$password) { 
    $id=$this->new_id(); 
    $result=pg_query(user::connect(),"insert into user (id,email,password,ip,created_td) values ('2','{$email}','{$password}','0','0') "); 
    return pg_affected_rows($result); 
} 
} 

我使用$this->connect()但有一個錯誤: (

+0

哪一行是25? –

+0

$結果= pg_query(用戶:: 「按id DESC LIMIT 1 SELECT * FROM用戶順序」 連接(),); –

+0

或 $結果= pg_query(用戶::連接(),「插入用戶(ID,電子郵件,密碼,IP,created_td)值( '2', '{$電子郵件}', '{$密碼}', '0','0')「); 我的問題: '用戶:: connect()的' 如何連接? –

回答

1

您正在嘗試使用connect功能這裏的參數結果:pg_query (user::connect(), ...,但它沒有return語句,因此將評估爲null

你需要調用。 $this->connect()一次(你已經在構造函數中做過),然後通過$this->link,如pg_query($this->link, ...

+0

該死的我張貼了相同的答案:d – Bobot

+0

:d這是行不通的 –

+1

@ Bob0t對不起,恨它,當發生這種情況:) – IMSoP