ok i am having a really dense moment … not sure what you mean. :-[, i tried this …
[php]<?php
ini_set(‘error_reporting’, E_ALL);
ini_set(‘display_errors’, ‘1’);
try {
require_once (’./Connections/DB.php’);
$db = new DB();
} catch (Exception $e) {
echo ‘
Error:
’;
echo $e->getCode() . ‘: ’ . $e->getMessage();
echo ‘
Stack trace:
’;
foreach ($e->getTrace() as $trace) {
echo $trace[‘file’] . ’ Line #’ . $trace[‘line’] . ‘
’;
}
}
#$db-> query($sql, $params);
$STH = $db->prepare(“SELECT
IF(COUNT(class_1) >= 10, ‘disabled’, null) as disabled
FROM hot14
WHERE class_1 = ?”);
$ids = array(‘Option A-C’, ‘Option A-D’, ‘Option B-C’, ‘Option B-D’);
$fields = array();
foreach ($ids as $id) {
$STH->execute(array($id));
$result = $STH->fetch();
$fields[$id] = $result[‘disabled’];
}
?>[/php]
and got this:
[code]Notice: Undefined variable: sql in hot_reg14_2.php on line 17
Notice: Undefined variable: params in hot_reg14_2.php on line 17
Fatal error: Uncaught exception ‘PDOException’ with message ‘SQLSTATE[42000]:
Syntax error or access violation: 1065 Query was empty’ in DB.php:45
Stack trace:
#0 DB.php(45): PDO->prepare(’’)
#1 hot_reg14_2.php(17): DB->query(NULL, NULL)
#2 hot_2.php(53): include(’/homepages/23/d…’)
#3 {main} thrown in DB.php on line 45[/code]
and Dreamweaver is throwing errors on lines 44-58 of the DB.php
[php]<?php
class DB {
/**
*
* PDO connection
* @var PDO
*/
private $pdoConn = null;
/**
* Class constructor
*/
public function __construct() {
$this->_initDb();
}
/**
* Get PDO database connection
*
* @return
*/
public function getPDOConn() {
return $this->pdoConn;
}
/**
* Init db connection
*/
private function _initDb() {
$this->pdoConn = new \PDO('mysql:dbname=db451530158;host=db451530158.db.1and1.com;charset=utf8', 'dbo451530158', 'FOOLS2012');
$this->pdoConn->exec("set names utf8");
$this->pdoConn->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
$this->pdoConn->setAttribute(\PDO::ATTR_EMULATE_PREPARES, false);
}
/**
* Executes parametarized query
* @param string $query
* @param array $params
* @param string $fetch_method
*/
public function query($query, $params = [], $fetch_method = ‘OBJ’, $class = ‘’) {
$stmt = $this->pdoConn->prepare($query);
$result = $stmt->execute($params);
if ($result) {
$querybit = explode(" ", trim($query));
if ($querybit[0] == 'SELECT') {
if (strtoupper($fetch_method) === 'CLASS') {
$ret = $stmt->fetchAll(constant('PDO::FETCH_CLASS'), $class);
} else {
$ret = $stmt->fetchAll(constant('PDO::FETCH_' . strtoupper($fetch_method)));
}
} else {
$ret = [TRUE];
}
}
return !empty($ret) ? $ret : null;
}
/**
* Get last inserted id
*
* @return integer
*/
public function getLastInsertedId() {
return $this->pdoConn->lastInsertId();
}
/**
* Generate unnamed placeholders.
* Accepts an array of values that are to be inserted into the database.
*
* @param array $array
* @return string
*/
public function generatePlaceholders ($array) {
return rtrim(str_repeat('?,', count($array)), ',');
}
}[/php]