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'));