|
Posted by Sanders Kaufman on 07/21/07 20:39
Sanders Kaufman wrote:
> function CreateTable($sTableName, $sTableDef){
> //Returns true, or false with an ErrorMessage.
> //Prefixes table name and appends ISAM engine type.
> //Auto-creates id field, but user should still provide a unique
> field
> $bRetVal = true;
> $this->RecordSQL = "CREATE TABLE {$this->TablePrefix}_$sTableName
> (id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY (id),
> $sTableDef) ENGINE=MyISAM";
> if(!$this->RunSQL($this->RecordSQL)){
> $bRetVal = false;
> $this->ErrorMessage=mysql_error();
> } else {
> $this->ErrorMessage="OK";
> }
> return $bRetVal;
> }
This is actually one of the parts of my architecture I'm most proud of.
By specifying a table prefix in the class, it allows multiple web
applications to all use the same database, without any problem with same
names.
For example, suppose you use this framework to build a discussion forum
program. A client then uses it to build to web sites that use the same
database server (e.g. kaiser.kaufman.net and caesar.kaufman.net, both
using mysql.kaufman.net).
If the discussion forum uses a "users" table, then the developer can
isolate one from the other by specifying a unite table prefix.
Navigation:
[Reply to this message]
|