adoSchema::SetPrefix PHP Method

SetPrefix() public method

Call this method to set a standard prefix that will be prepended to all database tables and indices when the schema is parsed. Calling setPrefix with no arguments clears the prefix.
public SetPrefix ( string $prefix = '', boolean $underscore = TRUE ) : boolean
$prefix string Prefix that will be prepended.
$underscore boolean If TRUE, automatically append an underscore character to the prefix.
return boolean TRUE if successful, else FALSE
    function SetPrefix($prefix = '', $underscore = TRUE)
    {
        switch (TRUE) {
            // clear prefix
            case empty($prefix):
                logMsg('Cleared prefix');
                $this->objectPrefix = '';
                return TRUE;
                // prefix too long
                // prefix too long
            // prefix too long
            // prefix too long
            case strlen($prefix) > XMLS_PREFIX_MAXLEN:
                // prefix contains invalid characters
                // prefix contains invalid characters
            // prefix contains invalid characters
            // prefix contains invalid characters
            case !preg_match('/^[a-z][a-z0-9_]+$/i', $prefix):
                logMsg('Invalid prefix: ' . $prefix);
                return FALSE;
        }
        if ($underscore and substr($prefix, -1) != '_') {
            $prefix .= '_';
        }
        // prefix valid
        logMsg('Set prefix: ' . $prefix);
        $this->objectPrefix = $prefix;
        return TRUE;
    }

Usage Example

Example #1
0
            } else {
                echo_success("Good, database \"<b>{$db_name}</b>\" has been created!!");
                //Reconnect. Hrmm, this is kinda weird.
                $db->Connect($db_host, $db_user, $db_password, $db_name);
            }
        }
        break;
    default:
        echo_normal("Sorry, <b>setup.php</b> currently does not fully support \"<b>{$db_type}</b>\" databases.\n\t\t\t\t\t<br>I'm assuming you've already created the database \"{$db_name}\", attempting to create tables.\n\t\t\t\t\t<br> Please email <b>{$author_email}</b> code to detect if a database is created or not so full support for \"<b>{$db_type}</b>\" can be added.");
}
/*
 * Attempt to create tables
 */
// Create the schema object and build the query array.
$schema = new adoSchema($db);
$schema->SetPrefix($db_table_prefix, FALSE);
//set $underscore == FALSE
// Build the SQL array
$schema->ParseSchema('schema.xml');
// maybe display this if $gacl->debug is true?
if ($gacl->_debug) {
    print "Here's the SQL to do the build:<br />\n<code>";
    print $schema->getSQL('html');
    print "</code>\n";
    // exit;
}
// Execute the SQL on the database
#ADODB's xmlschema is being lame, continue on error.
$schema->ContinueOnError(TRUE);
$result = $schema->ExecuteSchema();
if ($result != 2) {
All Usage Examples Of adoSchema::SetPrefix