Advertisement
Advertisement
| 05.15.2008 at 08:53PM PDT, ID: 23407351 | Points: 500 |
|
[x]
Attachment Details
|
||
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: |
class DBTable {
private $aDBFields;
private $aAutoPrimaryField;
private $aPrimaries;
private $aData;
private $table;
function __construct($table,$aData = NULL) {
global $dbh;
// first get the list of fields in the database. You can use this array in your methods to constrain the fields that can be used in insert and update statements.
$sth = $dbh->prepare("DESCRIBE $table");
$sth->execute();
if( $sth->columnCount() ) {
while($aRow = $sth->fetch(PDO::FETCH_ASSOC)) {
$this->aDBFields[] = $aRow['Field'];
if( $aRow['Extra'] == 'auto_increment' ) {
$this->aAutoPrimaryField = $aRow['Field'];
}
if( $aRow['Key'] == 'PRI' ) {
$this->aPrimaries[] = $aRow['Field'];
}
}
// now store the data passed to the constructor
if( !is_null($aData) ) {
foreach($aData as $key => $value) {
$this->aData[$key] = $value;
}
}
$this->table = $table;
} else {
throw new Exception( 'MySQL Error: no such table as '.$table);
}
}
etc...
|