douyou7797 2013-05-18 11:31
浏览 86
已采纳

需要php配置类,但找不到文件

In my opinion I'm requiring all necessary files but I keep getting the error that one file is not found. All files are in the same folder.

This is my code for zConfig.php:

<?php
class zConfig {
    static $confArray;
    public static function read($name) {
        return self::$confArray[$name];
    }
    public static function write($name, $value) {
        self::$confArray[$name] = $value;
    }
}
?>

And this is my code for bd2.php:

require_once('zConfig.php');

/*
 * Write settings to the config
 */
zConfig::write('hostname', 'XXXX');
zConfig::write('database', 'XXXX');
zConfig::write('username', 'XXXX');
zConfig::write('password', 'XXXX');
zConfig::write('drivers', array(PDO::ATTR_PERSISTENT => true));

Finally, this is my code for a function within Product.php:

public function pdo_updateTip($which, $tiptext)
{
  require_once("bd2.php");
  try {
  $pdo = new PDO("mysql:host=".bd2::read('hostname').";dbname=".bd2::read('database')."", bd2::read('username'), bd2::read('password'), bd2::read('drivers'));
  $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

  $stmt = $pdo->prepare("UPDATE tip SET tip_text = :tiptext WHERE product_id='0' AND item LIKE :which");
  $stmt->execute(array(
    ':tiptext'   => $tiptext,
    ':which' => $which
  ));

echo $stmt->rowCount(); // 1
} catch(PDOException $e) {
  echo 'Error: ' . $e->getMessage();
}
    return true;
}

The error I'm getting when I load Product.php is this:

Fatal error: Class 'bd2' not found in /home/xxxxx/Product.php on line 45

Line 45 is the line where I first refer to bd2, here:

$pdo = new PDO("mysql:host=".bd2::read('hostname').";dbname=".bd2::read('database')."", bd2::read('username'), bd2::read('password'), bd2::read('drivers'));
  • 写回答

3条回答 默认 最新

  • douer9399 2013-05-18 11:41
    关注

    I think that what you want to do is

    $pdo = new PDO("mysql:host=".zConfig::read('hostname').";dbname=".zConfig::read('database')."", zConfig::read('username'), zConfig::read('password'), zConfig::read('drivers'));
    

    bd2 is not a class and therefore it does not contain any static method read. It seems that it is just a file that sets the configuration for your database by using the zConfig::write method.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?
  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用