ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
pdoDB Class Reference
+ Collaboration diagram for pdoDB:

Public Member Functions

 __construct ()
 
 nextId ($table_name)
 
 createTable ($table_name, $fields)
 experimental.... More...
 
 addPrimaryKey ($table_name, $primary_keys)
 
 createSequence ($table_name)
 
 tableExists ($table_name)
 
 tableColumnExists ($table_name, $column_name)
 
 addTableColumn ($table_name, $column_name, $attributes)
 
 dropTable ($table_name)
 
 query ($query)
 
 fetchAll ($query_result)
 
 dropSequence ($table_name)
 
 dropTableColumn ($table_name, $column_name)
 
 renameTableColumn ($table_name, $column_old_name, $column_new_name)
 
 insert ($table_name, $values)
 
 fetchObject ($query_result)
 
 update ($table_name, $values, $where)
 
 manipulate ($query)
 
 fetchAssoc ($query_result)
 
 numRows ($query_result)
 
 quote ($value, $type)
 
 addIndex ($table_name, $index_name)
 

Protected Member Functions

 createTableFields ($fields)
 

Protected Attributes

 $pdo
 
 $type_to_mysql_type
 

Static Protected Attributes

static $staticPbo
 

Detailed Description

Definition at line 3 of file class.pdoDB.php.

Constructor & Destructor Documentation

◆ __construct()

pdoDB::__construct ( )

Definition at line 25 of file class.pdoDB.php.

25 {
26 $this->pdo = new PDO('mysql:host=localhost;dbname=test_db;charset=utf8', 'travis', '');
27 $this->pdo->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
28 $attr = PDO::MYSQL_ATTR_USE_BUFFERED_QUERY;
29 }

Member Function Documentation

◆ addIndex()

pdoDB::addIndex (   $table_name,
  $index_name 
)
Parameters
$table_name
$index_name
Returns
null

Definition at line 311 of file class.pdoDB.php.

311 {
312 return NULL;
313 }

◆ addPrimaryKey()

pdoDB::addPrimaryKey (   $table_name,
  $primary_keys 
)
Parameters
$table_namestring
$primary_keysarray

Definition at line 90 of file class.pdoDB.php.

90 {
91 $keys = implode($primary_keys);
92 $this->pdo->exec("ALTER TABLE $table_name ADD PRIMARY KEY ($keys)");
93 }

◆ addTableColumn()

pdoDB::addTableColumn (   $table_name,
  $column_name,
  $attributes 
)
Parameters
$table_namestring
$column_namestring
$attributesarray

Definition at line 138 of file class.pdoDB.php.

138 {
139 $col = array( $column_name => $attributes );
140 $col_str = $this->createTableFields($col);
141 $this->pdo->exec("ALTER TABLE $$table_name ADD $$col_str");
142 }
createTableFields($fields)
Definition: class.pdoDB.php:71

References createTableFields().

+ Here is the call graph for this function:

◆ createSequence()

pdoDB::createSequence (   $table_name)
Parameters
$table_namestring

Definition at line 99 of file class.pdoDB.php.

99 {
100 //TODO
101 }

◆ createTable()

pdoDB::createTable (   $table_name,
  $fields 
)

experimental....

Parameters
$table_namestring
$fieldsarray

Definition at line 59 of file class.pdoDB.php.

59 {
60 $fields_query = $this->createTableFields($fields);
61 $query = "CREATE TABLE $table_name ($fields_query);";
62 $this->pdo->exec($query);
63 }

References $query, and createTableFields().

+ Here is the call graph for this function:

◆ createTableFields()

pdoDB::createTableFields (   $fields)
protected
Parameters
$fields
Returns
string

Definition at line 71 of file class.pdoDB.php.

71 {
72 $query = "";
73 foreach ($fields as $name => $field) {
74 $type = $this->type_to_mysql_type[$field['type']];
75 $length = $field['length'];
76 $primary = isset($field['is_primary']) && $field['is_primary'] ? "PRIMARY KEY" : "";
77 $notnull = isset($field['is_notnull']) && $field['is_notnull'] ? "NOT NULL" : "";
78 $sequence = isset($field['sequence']) && $field['sequence'] ? "AUTO_INCREMENT" : "";
79 $query .= "$name $type ($length) $sequence $primary $notnull,";
80 }
81
82 return substr($query, 0, - 1);
83 }

References $query.

Referenced by addTableColumn(), and createTable().

+ Here is the caller graph for this function:

◆ dropSequence()

pdoDB::dropSequence (   $table_name)
Parameters
$table_namestring

Definition at line 179 of file class.pdoDB.php.

179 {
180 $table_seq = $table_name . "_seq";
181 if ($this->tableExists($table_seq)) {
182 $this->pdo->exec("DROP TABLE $table_seq");
183 }
184 }
tableExists($table_name)

References tableExists().

+ Here is the call graph for this function:

◆ dropTable()

pdoDB::dropTable (   $table_name)
Parameters
$table_namestring

Definition at line 148 of file class.pdoDB.php.

148 {
149 $this->pdo->exec("DROP TABLE $table_name");
150 }

◆ dropTableColumn()

pdoDB::dropTableColumn (   $table_name,
  $column_name 
)
Parameters
$table_namestring
$column_namestring

Definition at line 191 of file class.pdoDB.php.

191 {
192 $this->pdo->exec("ALTER TABLE $$table_name DROP COLUMN $column_name");
193 }

◆ fetchAll()

pdoDB::fetchAll (   $query_result)
Parameters
$query_resultPDOStatement
Returns
array

Definition at line 171 of file class.pdoDB.php.

171 {
172 return $query_result->fetchAll($query_result);
173 }

◆ fetchAssoc()

pdoDB::fetchAssoc (   $query_result)
Parameters
$query_resultPDOStatement
Returns
mixed

Definition at line 271 of file class.pdoDB.php.

271 {
272 $res = $query_result->fetch(PDO::FETCH_ASSOC);
273 if ($res == NULL) {
274 $query_result->closeCursor();
275
276 return NULL;
277 }
278
279 return $res;
280 }

References $res.

◆ fetchObject()

pdoDB::fetchObject (   $query_result)
Parameters
$query_resultPDOStatement
Returns
mixed|null

Definition at line 225 of file class.pdoDB.php.

225 {
226 $res = $query_result->fetchObject();
227 if ($res == NULL) {
228 $query_result->closeCursor();
229
230 return NULL;
231 }
232
233 return $res;
234 }

References $res.

◆ insert()

pdoDB::insert (   $table_name,
  $values 
)
Parameters
$table_namestring
$values

Definition at line 210 of file class.pdoDB.php.

210 {
211 $real = array();
212 foreach ($values as $val) {
213 $real[] = $this->quote($val[1], $val[0]);
214 }
215 $values = implode(",", $real);
216 $this->pdo->exec("INSERT INTO $table_name VALUES ($values)");
217 }
quote($value, $type)

References quote().

+ Here is the call graph for this function:

◆ manipulate()

pdoDB::manipulate (   $query)
Parameters
$querystring

Definition at line 261 of file class.pdoDB.php.

261 {
262 $this->pdo->exec($query);
263 }

References $query.

◆ nextId()

pdoDB::nextId (   $table_name)
Parameters
$table_namestring
Returns
int

Definition at line 37 of file class.pdoDB.php.

37 {
38 if ($this->tableExists($table_name . '_seq')) {
39 $table_seq = $table_name . '_seq';
40 $stmt = $this->pdo->prepare("SELECT * FROM $table_seq");
41 $stmt->execute();
42 $rows = $stmt->fetch(PDO::FETCH_ASSOC);
43 $stmt->closeCursor();
44
45 return count($rows) ? 0 : $rows['seq'];
46 } else {
47 // return $this->pdo->lastInsertId($table_name) + 1;
48 return 0;
49 }
50 }

References tableExists().

+ Here is the call graph for this function:

◆ numRows()

pdoDB::numRows (   $query_result)
Parameters
$query_resultPDOStatement
Returns
int

Definition at line 288 of file class.pdoDB.php.

288 {
289 return $query_result->rowCount();
290 }

◆ query()

pdoDB::query (   $query)
Parameters
$querystring
Returns
\PDOStatement

Definition at line 158 of file class.pdoDB.php.

158 {
159 $res = $this->pdo->query($query);
160 $err = $this->pdo->errorInfo();
161
162 return $res;
163 }

References $query, and $res.

◆ quote()

pdoDB::quote (   $value,
  $type 
)
Parameters
$value
$type
Returns
string

Definition at line 299 of file class.pdoDB.php.

299 {
300 //TODO TYPE SENSITIVE.
301 return $this->pdo->quote($value);
302 }

Referenced by insert(), and update().

+ Here is the caller graph for this function:

◆ renameTableColumn()

pdoDB::renameTableColumn (   $table_name,
  $column_old_name,
  $column_new_name 
)
Parameters
$table_namestring
$column_old_namestring
$column_new_namestring

Definition at line 201 of file class.pdoDB.php.

201 {
202 $this->pdo->exec("alter table $table_name change $column_old_name $column_new_name");
203 }

◆ tableColumnExists()

pdoDB::tableColumnExists (   $table_name,
  $column_name 
)
Parameters
$table_namestring
$column_namestring
Returns
bool

Definition at line 125 of file class.pdoDB.php.

125 {
126 $statement = $this->pdo->query("SHOW COLUMNS FROM $table_name WHERE Field = '$column_name'");
127 $statement != NULL ? $statement->closeCursor() : "";
128
129 return $statement != NULL && $statement->rowCount() != 0;
130 }

◆ tableExists()

pdoDB::tableExists (   $table_name)
Parameters
$table_namestring
Returns
bool

Definition at line 109 of file class.pdoDB.php.

109 {
110 $result = $this->pdo->prepare("SHOW TABLES LIKE :table_name");
111 $result->execute(array( ':table_name' => $table_name ));
112 $return = $result->rowCount();
113 $result->closeCursor();
114
115 return $return > 0;
116 }
$result

References $result.

Referenced by dropSequence(), and nextId().

+ Here is the caller graph for this function:

◆ update()

pdoDB::update (   $table_name,
  $values,
  $where 
)
Parameters
$table_namestring
$valuesarray
$wherearray

Definition at line 242 of file class.pdoDB.php.

242 {
243 $query = "UPDATE $table_name SET ";
244 foreach ($values as $key => $val) {
245 $qval = $this->quote($val[1], $val[0]);
246 $query .= "$key=$qval,";
247 }
248 $query = substr($query, 0, - 1) . " WHERE ";
249 foreach ($where as $key => $val) {
250 $qval = $this->quote($val[1], $val[0]);
251 $query .= "$key=$qval,";
252 }
253 $query = substr($query, 0, - 1);
254 $this->pdo->exec($query);
255 }

References $query, and quote().

+ Here is the call graph for this function:

Field Documentation

◆ $pdo

pdoDB::$pdo
protected

Definition at line 8 of file class.pdoDB.php.

◆ $staticPbo

pdoDB::$staticPbo
staticprotected

Definition at line 9 of file class.pdoDB.php.

◆ $type_to_mysql_type

pdoDB::$type_to_mysql_type
protected
Initial value:
= array(
'text' => 'VARCHAR',
'integer' => 'INT',
'float' => 'DOUBLE',
'date' => 'DATE',
'time' => 'TIME',
'datetime' => 'TIMESTAMP',
'clob' => 'LONGTEXT',
)

Definition at line 13 of file class.pdoDB.php.


The documentation for this class was generated from the following file: