2014-12-21 107 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