62 $this->pdoObject=new \PDO($this->dbType.
':host=' . $this->serverName .
';dbname=' . $this->dbName .
';charset=UTF8;port:' . $this->port, $this->user, $this->password,$this->options);
63 $this->pdoObject->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
72 return $this->pdoObject->query($sql);
86 $result=$this->cache->fetch($tableName, $condition);
88 if ($result ===
false) {
90 $statement=$this->
getStatement(
"SELECT {$fields} FROM " . $tableName . $condition);
91 $statement->execute();
92 $result=$statement->fetchAll();
93 $statement->closeCursor();
95 $this->cache->store($tableName, $condition, $result);
106 if (!isset($this->statements[$sql])) {
107 $this->statements[$sql]=$this->pdoObject->prepare($sql);
108 $this->statements[$sql]->setFetchMode(\PDO::FETCH_ASSOC);
110 return $this->statements[$sql];
119 return $this->pdoObject->exec($sql);
136 return $this->pdoObject->prepare($sql);
147 return $statement->bindValue(
":" . $parameter, $value);
155 return $this->pdoObject->lastInsertId();
160 $query=$this->pdoObject->query($sql);
161 return $query->fetchAll(\PDO::FETCH_COLUMN);
169 public function count($tableName, $condition=
'') {
170 if ($condition !=
'')
171 $condition=
" WHERE " . $condition;
172 return $this->
query(
"SELECT COUNT(*) FROM " . $tableName . $condition)->fetchColumn();
176 return ($this->pdoObject!==null && $this->pdoObject instanceof \PDO);
connect()
Creates the PDO instance.
static getFieldList($fields)
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.
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.