64 $this->pdoObject=new \PDO($this->dbType.
':host=' . $this->serverName .
';dbname=' . $this->dbName .
';charset=UTF8;port:' . $this->port, $this->user, $this->password,$this->options);
65 $this->pdoObject->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
74 return $this->pdoObject->query($sql);
88 $result=$this->cache->fetch($tableName, $condition);
90 if ($result ===
false) {
92 $statement=$this->
getStatement(
"SELECT {$fields} FROM " . $tableName . $condition);
93 $statement->execute();
94 $result=$statement->fetchAll();
95 $statement->closeCursor();
97 $this->cache->store($tableName, $condition, $result);
108 if (!isset($this->statements[$sql])) {
109 $this->statements[$sql]=$this->pdoObject->prepare($sql);
110 $this->statements[$sql]->setFetchMode(\PDO::FETCH_ASSOC);
112 return $this->statements[$sql];
121 return $this->pdoObject->exec($sql);
138 return $this->pdoObject->prepare($sql);
149 return $statement->bindValue(
":" . $parameter, $value);
157 return $this->pdoObject->lastInsertId();
162 $query=$this->pdoObject->query($sql);
163 return $query->fetchAll(\PDO::FETCH_COLUMN);
171 public function count($tableName, $condition=
'') {
172 if ($condition !=
'')
173 $condition=
" WHERE " . $condition;
174 return $this->
query(
"SELECT COUNT(*) FROM " . $tableName . $condition)->fetchColumn();
178 return ($this->pdoObject!==null && $this->pdoObject instanceof \PDO);
connect()
Creates the PDO instance.
setServerName($serverName)
prepareStatement($sql)
Prepares a statement for execution and returns a statement object.
execute($sql)
Execute an SQL statement and return the number of affected rows (INSERT, UPDATE or DELETE) ...
prepareAndExecute($tableName, $condition, $fields, $useCache=NULL)
query($sql)
Executes an SQL statement, returning a result set as a PDOStatement object.
static getFieldList($fields, $tableName=false)
lastInserId()
Returns the last insert id.
__construct($dbType, $dbName, $serverName="localhost", $port="3306", $user="root", $password="", $options=[], $cache=false)
Constructor.
count($tableName, $condition='')
Returns the number of records in $tableName that respects the condition passed as a parameter...
bindValueFromStatement(\PDOStatement $statement, $parameter, $value)
Sets $value to $parameter.