ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
pdoDB Class Reference
+ Collaboration diagram for pdoDB:

Public Member Functions

 __construct ()
 nextId ($table_name)
 createTable ($table_name, $fields)
 experimental....
 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

pdoDB::__construct ( )

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

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

Member Function Documentation

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

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

{
return NULL;
}
pdoDB::addPrimaryKey (   $table_name,
  $primary_keys 
)
Parameters
$table_namestring
$primary_keysarray

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

{
$keys = implode($primary_keys);
$this->pdo->exec("ALTER TABLE $table_name ADD PRIMARY KEY ($keys)");
}
pdoDB::addTableColumn (   $table_name,
  $column_name,
  $attributes 
)
Parameters
$table_namestring
$column_namestring
$attributesarray

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

References createTableFields().

{
$col = array( $column_name => $attributes );
$col_str = $this->createTableFields($col);
$this->pdo->exec("ALTER TABLE $$table_name ADD $$col_str");
}

+ Here is the call graph for this function:

pdoDB::createSequence (   $table_name)
Parameters
$table_namestring

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

{
//TODO
}
pdoDB::createTable (   $table_name,
  $fields 
)

experimental....

Parameters
$table_namestring
$fieldsarray

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

References $query, and createTableFields().

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

+ Here is the call graph for this function:

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

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

References $query.

Referenced by addTableColumn(), and createTable().

{
$query = "";
foreach ($fields as $name => $field) {
$type = $this->type_to_mysql_type[$field['type']];
$length = $field['length'];
$primary = isset($field['is_primary']) && $field['is_primary'] ? "PRIMARY KEY" : "";
$notnull = isset($field['is_notnull']) && $field['is_notnull'] ? "NOT NULL" : "";
$sequence = isset($field['sequence']) && $field['sequence'] ? "AUTO_INCREMENT" : "";
$query .= "$name $type ($length) $sequence $primary $notnull,";
}
return substr($query, 0, - 1);
}

+ Here is the caller graph for this function:

pdoDB::dropSequence (   $table_name)
Parameters
$table_namestring

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

References tableExists().

{
$table_seq = $table_name . "_seq";
if ($this->tableExists($table_seq)) {
$this->pdo->exec("DROP TABLE $table_seq");
}
}

+ Here is the call graph for this function:

pdoDB::dropTable (   $table_name)
Parameters
$table_namestring

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

{
$this->pdo->exec("DROP TABLE $table_name");
}
pdoDB::dropTableColumn (   $table_name,
  $column_name 
)
Parameters
$table_namestring
$column_namestring

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

{
$this->pdo->exec("ALTER TABLE $$table_name DROP COLUMN $column_name");
}
pdoDB::fetchAll (   $query_result)
Parameters
$query_resultPDOStatement
Returns
array

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

{
return $query_result->fetchAll($query_result);
}
pdoDB::fetchAssoc (   $query_result)
Parameters
$query_resultPDOStatement
Returns
mixed

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

References $res.

{
$res = $query_result->fetch(PDO::FETCH_ASSOC);
if ($res == NULL) {
$query_result->closeCursor();
return NULL;
}
return $res;
}
pdoDB::fetchObject (   $query_result)
Parameters
$query_resultPDOStatement
Returns
mixed|null

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

References $res.

{
$res = $query_result->fetchObject();
if ($res == NULL) {
$query_result->closeCursor();
return NULL;
}
return $res;
}
pdoDB::insert (   $table_name,
  $values 
)
Parameters
$table_namestring
$values

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

References quote().

{
$real = array();
foreach ($values as $val) {
$real[] = $this->quote($val[1], $val[0]);
}
$values = implode(",", $real);
$this->pdo->exec("INSERT INTO $table_name VALUES ($values)");
}

+ Here is the call graph for this function:

pdoDB::manipulate (   $query)
Parameters
$querystring

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

References $query.

{
$this->pdo->exec($query);
}
pdoDB::nextId (   $table_name)
Parameters
$table_namestring
Returns
int

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

References tableExists().

{
if ($this->tableExists($table_name . '_seq')) {
$table_seq = $table_name . '_seq';
$stmt = $this->pdo->prepare("SELECT * FROM $table_seq");
$stmt->execute();
$rows = $stmt->fetch(PDO::FETCH_ASSOC);
$stmt->closeCursor();
return count($rows) ? 0 : $rows['seq'];
} else {
// return $this->pdo->lastInsertId($table_name) + 1;
return 0;
}
}

+ Here is the call graph for this function:

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

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

{
return $query_result->rowCount();
}
pdoDB::query (   $query)
Parameters
$querystring
Returns

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

References $query, and $res.

{
$res = $this->pdo->query($query);
$err = $this->pdo->errorInfo();
return $res;
}
pdoDB::quote (   $value,
  $type 
)
Parameters
$value
$type
Returns
string

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

Referenced by insert(), and update().

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

+ Here is the caller graph for this function:

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.

{
$this->pdo->exec("alter table $table_name change $column_old_name $column_new_name");
}
pdoDB::tableColumnExists (   $table_name,
  $column_name 
)
Parameters
$table_namestring
$column_namestring
Returns
bool

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

{
$statement = $this->pdo->query("SHOW COLUMNS FROM $table_name WHERE Field = '$column_name'");
$statement != NULL ? $statement->closeCursor() : "";
return $statement != NULL && $statement->rowCount() != 0;
}
pdoDB::tableExists (   $table_name)
Parameters
$table_namestring
Returns
bool

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

References $result.

Referenced by dropSequence(), and nextId().

{
$result = $this->pdo->prepare("SHOW TABLES LIKE :table_name");
$result->execute(array( ':table_name' => $table_name ));
$return = $result->rowCount();
$result->closeCursor();
return $return > 0;
}

+ Here is the caller graph for this function:

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

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

References $query, and quote().

{
$query = "UPDATE $table_name SET ";
foreach ($values as $key => $val) {
$qval = $this->quote($val[1], $val[0]);
$query .= "$key=$qval,";
}
$query = substr($query, 0, - 1) . " WHERE ";
foreach ($where as $key => $val) {
$qval = $this->quote($val[1], $val[0]);
$query .= "$key=$qval,";
}
$query = substr($query, 0, - 1);
$this->pdo->exec($query);
}

+ Here is the call graph for this function:

Field Documentation

pdoDB::$pdo
protected

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

pdoDB::$staticPbo
staticprotected

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

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: