db::prefix PHP Method

prefix() static public method

Adds a prefix to a table name if set in c::set('db.prefix', 'myprefix_'); This makes it possible to use table names in all methods without prefix and it will still be applied automatically.
static public prefix ( string $table ) : string
$table string The name of the table with or without prefix
return string The sanitized table name.
    static function prefix($table)
    {
        $prefix = c::get('db.prefix');
        if (!$prefix) {
            return $table;
        }
        return !str::contains($table, $prefix) ? $prefix . $table : $table;
    }

Usage Example

Example #1
0
}
session_start();
$router = array();
if (file_exists(APP_PATH . 'router.php')) {
    $router = (include APP_PATH . 'router.php');
}
$_uri = router($router);
define('MODULE', $_uri['module']);
define('ACTION', $_uri['action']);
require CORE_PATH . '/db.php';
$db = new db();
if (isset($config['DB_DRIVER'])) {
    $db->set_driver($config['DB_DRIVER']);
}
if (isset($config['DB_PREFIX'])) {
    $db->prefix($config['DB_PREFIX']);
}
$db_host = $config['DB_HOST'] . (isset($config['DB_PORT']) ? ':' . $config['DB_PORT'] : '');
$db->setting($db_host, $config['DB_USER'], $config['DB_PSWD'], $config['DB_NAME']);
$script = APP_PATH . 'action/' . MODULE . 'Action.php';
if (!file_exists($script)) {
    error_404('Can not find the action ' . MODULE . 'Action.php');
} else {
    require $script;
    $class = MODULE . 'Action';
    $method = ACTION;
    if ($method != $class) {
        $run = new $class();
        if (is_callable(array($run, $method))) {
            $run->{$method}();
        } else {
All Usage Examples Of db::prefix