PDO ve PDOStatement, büyülü atamaları

1 Cevap php

I have the following "test-class" made on the fly: http://sumoin.pastebin.com/ff744ea4 No fine-tuning or something else, just a brief testing pdo class.

And I have the test.php: http://sumoin.pastebin.com/d70dcb4ec

Komik bir şey:

PDOStatement nesnesi doğrudan asla geri döndü ve ben $this->handler->stmt atanan geçmez

but the executing $stmt->execute() works as fine as if everything is okey. But if I use $this->handler->stmt->someMethod I get the following error:

Fatal error: Call to a member function bindParam() on a non-object

(BindParam sadece bir örnektir)

I already checked the query, and it has no mistakes in it, I tried to use "bindValue()", did not work. I tried to use integers instead of ':name' to assign values to parameters. I ran the pure query through the $this->handler->query() and it worked.

Where is the problem located? I do not want to assign my PDOStatement object while the runtime, I want it to be part of the class, when the "->prepare()" method is called.

Any ideas? Please don't hit me if there is a duplicate out there, but I did not found anything that helped me.

Bilgi:

  • PHP5.2
  • PDO Uzantıları vb yüklü
  • Apache2
  • MySQL5.1 (PDO sürüme uygun)

1 Cevap

Çözüm / Çözüm:

public function prepare($query)
{
	return $this->handler->prepare($query);

	//$stmt->setFetchMode(PDO::FETCH_ASSOC); // standard
	//return $this->stmt;
}

public function getStatement($query)
{
	$this->stmt = $this->prepare($query);
}