ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 26 of file class.pdoDB.php.

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

Member Function Documentation

◆ addIndex()

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

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

335  {
336  return null;
337  }

◆ addPrimaryKey()

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

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

References $keys.

96  {
97  $keys = implode($primary_keys);
98  $this->pdo->exec("ALTER TABLE $table_name ADD PRIMARY KEY ($keys)");
99  }
$keys

◆ addTableColumn()

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

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

References $attributes, array, and createTableFields().

148  {
149  $col = array( $column_name => $attributes );
150  $col_str = $this->createTableFields($col);
151  $this->pdo->exec("ALTER TABLE $$table_name ADD $$col_str");
152  }
$attributes
Create styles array
The data for the language used.
createTableFields($fields)
Definition: class.pdoDB.php:75
+ Here is the call graph for this function:

◆ createSequence()

pdoDB::createSequence (   $table_name)
Parameters
$table_namestring

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

106  {
107  //TODO
108  }

◆ createTable()

pdoDB::createTable (   $table_name,
  $fields 
)

experimental....

Parameters
$table_namestring
$fieldsarray

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

References $query, and createTableFields().

63  {
64  $fields_query = $this->createTableFields($fields);
65  $query = "CREATE TABLE $table_name ($fields_query);";
66  $this->pdo->exec($query);
67  }
$query
createTableFields($fields)
Definition: class.pdoDB.php:75
+ Here is the call graph for this function:

◆ createTableFields()

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

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

References $name, $query, and $type.

Referenced by addTableColumn(), and createTable().

76  {
77  $query = "";
78  foreach ($fields as $name => $field) {
79  $type = $this->type_to_mysql_type[$field['type']];
80  $length = $field['length'];
81  $primary = isset($field['is_primary']) && $field['is_primary'] ? "PRIMARY KEY" : "";
82  $notnull = isset($field['is_notnull']) && $field['is_notnull'] ? "NOT NULL" : "";
83  $sequence = isset($field['sequence']) && $field['sequence'] ? "AUTO_INCREMENT" : "";
84  $query .= "$name $type ($length) $sequence $primary $notnull,";
85  }
86 
87  return substr($query, 0, -1);
88  }
$type
if($format !==null) $name
Definition: metadata.php:146
$query
+ Here is the caller graph for this function:

◆ dropSequence()

pdoDB::dropSequence (   $table_name)
Parameters
$table_namestring

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

References tableExists().

193  {
194  $table_seq = $table_name . "_seq";
195  if ($this->tableExists($table_seq)) {
196  $this->pdo->exec("DROP TABLE $table_seq");
197  }
198  }
tableExists($table_name)
+ Here is the call graph for this function:

◆ dropTable()

pdoDB::dropTable (   $table_name)
Parameters
$table_namestring

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

159  {
160  $this->pdo->exec("DROP TABLE $table_name");
161  }

◆ dropTableColumn()

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

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

206  {
207  $this->pdo->exec("ALTER TABLE $$table_name DROP COLUMN $column_name");
208  }

◆ fetchAll()

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

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

184  {
185  return $query_result->fetchAll($query_result);
186  }

◆ fetchAssoc()

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

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

References $res.

292  {
293  $res = $query_result->fetch(PDO::FETCH_ASSOC);
294  if ($res == null) {
295  $query_result->closeCursor();
296 
297  return null;
298  }
299 
300  return $res;
301  }
foreach($_POST as $key=> $value) $res

◆ fetchObject()

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

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

References $res.

243  {
244  $res = $query_result->fetchObject();
245  if ($res == null) {
246  $query_result->closeCursor();
247 
248  return null;
249  }
250 
251  return $res;
252  }
foreach($_POST as $key=> $value) $res

◆ insert()

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

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

References array, and quote().

227  {
228  $real = array();
229  foreach ($values as $val) {
230  $real[] = $this->quote($val[1], $val[0]);
231  }
232  $values = implode(",", $real);
233  $this->pdo->exec("INSERT INTO $table_name VALUES ($values)");
234  }
Create styles array
The data for the language used.
quote($value, $type)
+ Here is the call graph for this function:

◆ manipulate()

pdoDB::manipulate (   $query)
Parameters
$querystring

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

References $query.

281  {
282  $this->pdo->exec($query);
283  }
$query

◆ nextId()

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

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

References $rows, and tableExists().

40  {
41  if ($this->tableExists($table_name . '_seq')) {
42  $table_seq = $table_name . '_seq';
43  $stmt = $this->pdo->prepare("SELECT * FROM $table_seq");
44  $stmt->execute();
45  $rows = $stmt->fetch(PDO::FETCH_ASSOC);
46  $stmt->closeCursor();
47 
48  return count($rows) ? 0 : $rows['seq'];
49  } else {
50  // return $this->pdo->lastInsertId($table_name) + 1;
51  return 0;
52  }
53  }
tableExists($table_name)
$rows
Definition: xhr_table.php:10
+ Here is the call graph for this function:

◆ numRows()

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

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

310  {
311  return $query_result->rowCount();
312  }

◆ query()

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

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

References $query, and $res.

170  {
171  $res = $this->pdo->query($query);
172  $err = $this->pdo->errorInfo();
173 
174  return $res;
175  }
foreach($_POST as $key=> $value) $res
$query

◆ quote()

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

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

Referenced by insert(), and update().

322  {
323  //TODO TYPE SENSITIVE.
324  return $this->pdo->quote($value);
325  }
+ 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 216 of file class.pdoDB.php.

217  {
218  $this->pdo->exec("alter table $table_name change $column_old_name $column_new_name");
219  }

◆ tableColumnExists()

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

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

134  {
135  $statement = $this->pdo->query("SHOW COLUMNS FROM $table_name WHERE Field = '$column_name'");
136  $statement != null ? $statement->closeCursor() : "";
137 
138  return $statement != null && $statement->rowCount() != 0;
139  }

◆ tableExists()

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

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

References $result, and array.

Referenced by dropSequence(), and nextId().

117  {
118  $result = $this->pdo->prepare("SHOW TABLES LIKE :table_name");
119  $result->execute(array( ':table_name' => $table_name ));
120  $return = $result->rowCount();
121  $result->closeCursor();
122 
123  return $return > 0;
124  }
$result
Create styles array
The data for the language used.
+ Here is the caller graph for this function:

◆ update()

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

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

References $key, $query, and quote().

261  {
262  $query = "UPDATE $table_name SET ";
263  foreach ($values as $key => $val) {
264  $qval = $this->quote($val[1], $val[0]);
265  $query .= "$key=$qval,";
266  }
267  $query = substr($query, 0, -1) . " WHERE ";
268  foreach ($where as $key => $val) {
269  $qval = $this->quote($val[1], $val[0]);
270  $query .= "$key=$qval,";
271  }
272  $query = substr($query, 0, -1);
273  $this->pdo->exec($query);
274  }
$query
quote($value, $type)
$key
Definition: croninfo.php:18
+ Here is the call graph for this function:

Field Documentation

◆ $pdo

pdoDB::$pdo
protected

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

◆ $staticPbo

pdoDB::$staticPbo
staticprotected

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

◆ $type_to_mysql_type

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

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


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