Witam forumowiczów, czy ktoś ma jakiś pomysł na rozwiązanie problemu,
błąd interpretera Fatal error: Uncaught exception 'Exception' with message 'DB Error: syntax error' in /admin1/src/class.Database.php:153 Stack trace: #0 /admin1/src/class.UserSession.php(43): Database->delete('sesja_uzytkowni...', '(identyfikator_...') #1 /admin1/src/class.UserSession.php(61): UserSession->__construct() #2 /admin1/index.php(7): UserSession::instance() #3 {main} thrown in /admin1/src/class.Database.php on line 153
poniżej kod:
<?php
class_exists('Debugger') || require('class.Debugger.php');
//include_once'config.php';
require_once('DB.php');
//require_once('class.Debugger.php');
class Database {
private $conn;
private $numrows;
private function __construct($dsn = null) {
global $cfg;
//echo $cfg['db']['dsn'];
if(is_null($dsn)) {
$dsn = $cfg['db']['dsn'];
}
//echo $dsn;
$this->conn = DB::connect($dsn);
if(DB::isError($this->conn)) {
throw new Exception($this->conn->getMessage(), $this->conn->getCode());
}
$this->conn->setFetchMode(DB_FETCHMODE_ASSOC);
}
public static function instance($dsn=null) {
static $objDB;
if(!isset($objDB)) {
$objDB = new Database($dsn);
}
return $objDB;
}
public function __destruct() {
$this->conn->disconnect();
}
public function getNumRows(){
return $this->numrows;
}
public function select($sql) {
$result = $this->conn->query($sql);
if(DB::isError($result)) {
throw new Exception($result->getMessage(), $result->getCode());
}
$this->numrows = count($result);
return $result;
}
public function getAll($sql) {
$result = $this->conn->getAll($sql);
//echo $sql;
if(DB::isError($result)) {
throw new Exception($result->getMessage(), $result->getCode());
}
$this->numrows = count($result);
return $result;
}
public function getOne($sql) {
$result = $this->conn->getOne($sql);
if(DB::isError($result)) {
throw new Exception($result->getMessage(), $result->getCode());
}
return $result;
}
public function getRow($sql) {
$result = $this->conn->getRow($sql);
if (PEAR::isError($data)) {
throw new Exception($result->getMessage(), $result->getCode());
}
return $result;
}
public function getCol($sql) {
$result = $this->conn->getCol($sql);
if(DB::isError($result)) {
throw new Exception($result->getMessage(), $result->getCode());
}
$this->numrows = count($result);
return $result;
}
public function update($tableName, $arUpdate, $sWhere) {
if($sWhere) {
foreach($arUpdate as $name => $value) {
$arSet[] = $name . ' = ' . $this->conn->quoteSmart($value);
}
$sSet = implode(', ', $arSet);
$tableName = $this->conn->quoteIdentifier($tableName);
$sql = "UPDATE $tableName SET $sSet";
$sql .= " WHERE $sWhere";
//Debugger::debug($sql, "SQL UPDATE", DEBUG_SQL);
//echo $sql;
$result = $this->conn->query($sql);
if(DB::isError($result)) {
throw new Exception($result->getMessage(), $result->getCode());
}
return $this->conn->affectedRows();
}else {
throw new Exception("Brak warunku WHERE!");
}
}
public function insert($tableName, $arValues) {
$id = null;
//Debugger::debug($arValues, "trablica elementów przekazanych");
$sFiledList = implode(', ', array_keys($arValues));
//Debugger::debug($sFiledList,"lista nazw");
$arValuesList = array();
foreach ($arValues as $value) {
$arValuesList[] = $this->conn->quoteSmart($value);
//Debugger::debug($arValuesList,"lista wartosci");
}
$sValueList = implode(', ', $arValuesList);
$tableName = $this->conn->quoteIdentifier($tableName);
$sql = "INSERT INTO $tableName ( $sFiledList) VALUES ( $sValueList)";
//echo $sql;
$result = $this->conn->query($sql);
if(DB::isError($result)) {
throw new Exception($result->getMessage(), $result->getCode());
}
return $this->conn->affectedRows();
}
public function delete($tableName, $sWhere) {
if($sWhere) {
$sql = "DELETE FROM $tableName";
$sql .= "WHERE $sWhere";
//echo $sql;
$result = $this->conn->query($sql);
if(DB::isError($result)) {
throw new Exception($result->getMessage(), $result->getCode());
}
return $this->conn->affectedRows();
}else {
throw new Exception("Brak warunku WHERE!");
}
}
public function query($sql) {
$result = $this->conn->query($sql);
if(DB::isError($result)) {
throw new Exception($result->getMessage(), $result->getCode()); **tu gdzieś error? **
}
return $this->conn->affectedRows();
}
public function startTransaction() {
return $this->conn->autoCommit(false);
}
public function commit() {
$result = $this->conn->commit();
if(DB::isError($result)) {
throw new Exception($result->getMessage(), $result->getCode());
}
$this->conn->autoCommit(true);
return true;
}
public function abort() {
$result = $this->conn->rollback();
if(DB::isError($result)) {
throw new Exception($result->getMessage(), $result->getCode());
}
return true;
}
}
?>