gpt4 book ai didi

php - Zend_Db 的包装失败

转载 作者:行者123 更新时间:2023-11-29 14:57:21 24 4
gpt4 key购买 nike

全部,

我编写了以下包装器,它扩展了 Zend_Db 类,为我的整个应用程序提供数据库连接。数据库连接工作正常,但从不同的类调用时无法执行查询。

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;
}
}

尝试在包含 Testapp_DB 的 PHP 文件中执行查询 - 失败..

<?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 方法失败吗?

谢谢

最佳答案

*Zend_Db* 除了 factory() 之外没有任何方法。

我真的不明白,你想用这种方式解决什么问题,但据我所知,你需要这样调用query()

$db->db->query();

关于php - Zend_Db 的包装失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4270826/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com