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) |
Detailed Description
Definition at line 3 of file class.pdoDB.php.
Constructor & Destructor Documentation
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 |
|
) |
| |
pdoDB::addPrimaryKey |
( |
|
$table_name, |
|
|
|
$primary_keys |
|
) |
| |
- Parameters
-
$table_name | string |
$primary_keys | array |
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_name | string |
$column_name | string |
$attributes | array |
Definition at line 138 of file class.pdoDB.php.
References createTableFields().
{
$col = array( $column_name => $attributes );
$this->pdo->exec("ALTER TABLE $$table_name ADD $$col_str");
}
pdoDB::createSequence |
( |
|
$table_name | ) |
|
pdoDB::createTable |
( |
|
$table_name, |
|
|
|
$fields |
|
) |
| |
pdoDB::createTableFields |
( |
|
$fields | ) |
|
|
protected |
- Parameters
-
- Returns
- string
Definition at line 71 of file class.pdoDB.php.
References $query.
Referenced by addTableColumn(), and createTable().
{
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);
}
pdoDB::dropSequence |
( |
|
$table_name | ) |
|
- Parameters
-
Definition at line 179 of file class.pdoDB.php.
References tableExists().
{
$table_seq = $table_name . "_seq";
$this->pdo->exec("DROP TABLE $table_seq");
}
}
pdoDB::dropTable |
( |
|
$table_name | ) |
|
- Parameters
-
Definition at line 148 of file class.pdoDB.php.
{
$this->pdo->exec("DROP TABLE $table_name");
}
pdoDB::dropTableColumn |
( |
|
$table_name, |
|
|
|
$column_name |
|
) |
| |
- Parameters
-
$table_name | string |
$column_name | string |
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_result | PDOStatement |
- Returns
- array
Definition at line 171 of file class.pdoDB.php.
{
return $query_result->fetchAll($query_result);
}
pdoDB::fetchAssoc |
( |
|
$query_result | ) |
|
- Parameters
-
$query_result | PDOStatement |
- Returns
- mixed
Definition at line 271 of file class.pdoDB.php.
References $res.
{
$res = $query_result->fetch(PDO::FETCH_ASSOC);
$query_result->closeCursor();
return NULL;
}
}
pdoDB::fetchObject |
( |
|
$query_result | ) |
|
- Parameters
-
$query_result | PDOStatement |
- Returns
- mixed|null
Definition at line 225 of file class.pdoDB.php.
References $res.
{
$res = $query_result->fetchObject();
$query_result->closeCursor();
return NULL;
}
}
pdoDB::insert |
( |
|
$table_name, |
|
|
|
$values |
|
) |
| |
- Parameters
-
$table_name | string |
$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)");
}
pdoDB::manipulate |
( |
|
$query | ) |
|
pdoDB::nextId |
( |
|
$table_name | ) |
|
- Parameters
-
- Returns
- int
Definition at line 37 of file class.pdoDB.php.
References tableExists().
{
$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 0;
}
}
pdoDB::numRows |
( |
|
$query_result | ) |
|
- Parameters
-
$query_result | PDOStatement |
- Returns
- int
Definition at line 288 of file class.pdoDB.php.
{
return $query_result->rowCount();
}
pdoDB::quote |
( |
|
$value, |
|
|
|
$type |
|
) |
| |
pdoDB::renameTableColumn |
( |
|
$table_name, |
|
|
|
$column_old_name, |
|
|
|
$column_new_name |
|
) |
| |
- Parameters
-
$table_name | string |
$column_old_name | string |
$column_new_name | string |
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_name | string |
$column_name | string |
- 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 | ) |
|
pdoDB::update |
( |
|
$table_name, |
|
|
|
$values, |
|
|
|
$where |
|
) |
| |
- Parameters
-
$table_name | string |
$values | array |
$where | array |
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]);
}
foreach ($where as $key => $val) {
$qval = $this->
quote($val[1], $val[0]);
}
}
Field Documentation
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: