私はアプリケーション全体にdb接続を提供するためにZend_Dbクラスを拡張する以下のラッパーを作成しました。 db接続は正常に動作しますが、別のクラスから呼び出されたときにはクエリを実行できません。 Testapp_DBを含んでPHPファイルにクエリを実行しようとすると
class Testapp_DB extends Zend_Db {
//Declare member variables.
public $db = null;
public $db_host = "";
public $db_database = "";
public $db_username = "";
public $db_password = "";
public function __construct()
{
//Read Database Info from Config File
$this->db_host = Testapp_Registry::get('config')->db->mysql->host;
$this->db_database = Testapp_Registry::get('config')->db->mysql->dbname;
$this->db_username = Testapp_Registry::get('config')->db->mysql->username;
$this->db_password = Testapp_Registry::get('config')->db->mysql->password;
$db = Zend_Db::factory('Mysqli', array(
'host' => $this->db_host,
'username' => $this->db_username,
'password' => $this->db_password,
'dbname' => $this->db_database
));
$db->getConnection(); //Works fine
$this->db = $db;
}
}
- 失敗した...
<?php
$db = new Testapp_DB();
print_r($db); //I can see the DB object here
$sql = 'SELECT * FROM tb_Log';
$result = $db->fetchAll($sql, 2); //This method fails.. Don't know why. Any ideas?
print_r($result);
?>
のはfetchAllメソッドが失敗した理由を誰かが、説明していただけますか?
ありがとうございました。これはうまく動作します。$ db-> db-> query()の代わりに$ db-> query()にアクセスできるように、Testapp_DBクラスをどのように変更できますか?シングルトンパターンを追加できますか? – Jake
Nevermind ..シングルトンパターンを作成して – Jake