Commit d531f032 authored by Alex Ne's avatar Alex Ne

Багфикс

parent 537da486
......@@ -73,6 +73,7 @@ class PDO {
$this->Credetional->get_username(),
$this->Credetional->get_password());
$this->PDO->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
//$this->PDO->setAttribute(\PDO::ATTR_STATEMENT_CLASS, ['X\Database\Driver\PDOStatement', [$this->PDO]]);
$this->set_charset();
} catch (\PDOException $e) {
throw new PDO_ConnectionError("Connection to database error", 1, [
......@@ -189,6 +190,7 @@ class PDO {
* @param $SQL
*/
public function prepare($SQL) {
return new PDOStatement($this->PDO, $SQL);
return $this->PDO->prepare($SQL);
}
......@@ -239,7 +241,7 @@ class PDO {
*/
public function simple($table, $where = [], $order = null, $limit = null, $columns = "*") {
$statement = $this->select_statement($table, $where, $order, 1, $columns);
if ($statement->columnCount() > 0) {
if ($statement->rowCount() > 0) {
return $statement->fetchAll(\PDO::FETCH_ASSOC)[0];
} else {
return false;
......@@ -299,6 +301,12 @@ class PDO {
$columns = "*";
}
}
public function __sleep() {
return ['Credetional'];
}
public function __wakeup() {}
}
?>
\ No newline at end of file
<?php
namespace X\Database\Driver;
use \X\ETrace\System as ESys;
class PDOStatement {
/**
* @var mixed
*/
protected $db;
/**
* @var mixed
*/
protected $prepare;
/**
* @param $db
*/
public function __construct($db, $sql) {
$this->db = $db;
$this->prepare = $this->db->prepare($sql);
}
/**
* @param $parameter
* @param $value
* @param $data_type
*/
public function bindValue($parameter, $value, $data_type = \PDO::PARAM_STR) {
return $this->prepare->bindValue($parameter, $value, $data_type);
}
/**
* @param $input_parameters
*/
public function execute($input_parameters = null) {
if ($input_parameters == null) {
return $this->prepare->execute();
} else {
return $this->prepare->execute($input_parameters);
}
}
/**
* @param $fetch_style
* @param null $cursor_orientation
* @param \PDOFETCH_ORI_NEXT $cursor_offset
* @return mixed
*/
public function fetch($fetch_style = null, $cursor_orientation = \PDO::FETCH_ORI_NEXT, $cursor_offset = 0) {
if ($fetch_style == null) {
return $this->prepare->fetch();
} else {
return $this->prepare->fetch($fetch_style, $cursor_orientation, $cursor_offset);
}
}
/**
* @param $fetch_style
* @param null $fetch_argument
* @param array $ctor_args
* @return mixed
*/
public function fetchAll($fetch_style = null, $fetch_argument = null, $ctor_args = []) {
if ($fetch_style == null) {
return $this->prepare->fetchAll();
} else if ($fetch_argument == null) {
return $this->prepare->fetchAll($fetch_style);
} else {
return $this->prepare->fetchAll($fetch_style, $fetch_argument, $ctor_args);
}
}
/**
* @return mixed
*/
public function rowCount() {
return $this->prepare->rowCount();
}
/**
* @return mixed
*/
public function columnCount() {
return $this->prepare->columnCount();
}
/**
* @param $attribute
* @param $value
* @return mixed
*/
public function setAttribute($attribute, $value) {
return $this->prepare->setAttribute($attribute, $value);
}
/**
* @param $mode
* @return mixed
*/
public function setFetchMode($mode) {
return $this->prepare->setFetchMode($mode);
}
public function __sleep() {return [];}
public function __wakeup() {}
}
?>
\ No newline at end of file
......@@ -38,6 +38,7 @@ class PDOWhereConstructor {
* @param $data
*/
public function __construct($data = []) {
$this->data_set = [];
$this->Parse($data);
}
......@@ -60,7 +61,7 @@ class PDOWhereConstructor {
*/
public function Parse($data = []) {
if (is_array($data)) {
if (count($data > 0)) {
if (count($data) > 0) {
$this->SQL = "WHERE ";
$this->SQL .= $this->build_where_string($data);
} else {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment