コード例 #1
1
ファイル: crud.php プロジェクト: hassanazimi/PostgreSQL
function _init()
{
    global $CRUD;
    $CRUD['TITLE'] = "CRUD APP";
    $CRUD['SELF'] = $_SERVER["SCRIPT_NAME"];
    // loose "index.php" if nec (regexes are fugly in php. Feh.)
    $CRUD["SELF"] = preg_replace('/([\\/\\\\])index\\.php$/i', '$1', $CRUD["SELF"]);
    foreach (array('DBVERSION', 'BUTTONS', 'HIDDENS', 'MESSAGES', 'ERRORS', 'CONTENT', 'PRECONTENT', 'POSTCONTENT', 'Atitle', 'Aartist', 'Alabel', 'Areleased_day', 'Areleased_month', 'Areleased_year', 'Ttrack_number', 'Ttitle', 'Tduration') as $v) {
        $CRUD[$v] = '';
    }
    switch (DBENGINE) {
        case 'sqlite3':
            try {
                $dbh = new PDO('sqlite:' . DBFILE, 'unused', 'unused');
                $dbh->sqliteCreateFunction('SEC_TO_TIME', 'sec_to_time', 1);
                // custom functions ...
                $dbh->sqliteCreateFunction('TIME_TO_SEC', 'time_to_sec', 1);
                $dbh->sqliteCreateAggregate('SUM_SEC_TO_TIME', 'sum_sec_to_time_step', 'sum_sec_to_time_finalize', 1);
                $CRUD['DBVERSION'] = SQLite3::version();
                $CRUD['DBVERSION'] = 'SQLite version ' . $CRUD['DBVERSION']['versionString'];
            } catch (PDOException $e) {
                error($e->getMessage());
            }
            break;
        case 'mysql':
            // connect to the database (persistent)
            try {
                $dbh = new PDO('mysql:host=localhost;dbname=' . MYSQLDB, MYSQLUSER, MYSQLPASS, array(PDO::ATTR_PERSISTENT => true));
                $sth = $dbh->query("SHOW VARIABLES WHERE variable_name = 'version'");
                $CRUD['DBVERSION'] = 'MySQL server version ' . $sth->fetchColumn(1);
                if ($dbh) {
                    set_mysql_album_len_function($dbh);
                }
            } catch (PDOException $e) {
                error($e->getMessage());
            }
            break;
        case 'pgsql':
            // connect to the database (persistent)
            try {
                $dbh = new PDO('pgsql:host=localhost;port=5432;dbname=' . PGSQLDB, PGSQLUSER, PGSQLPASS, array(PDO::ATTR_PERSISTENT => true));
                $dbh->exec("set client_encoding to 'latin1'");
                $sth = $dbh->query('SELECT VERSION()');
                $CRUD['DBVERSION'] = explode(' ', $sth->fetchColumn());
                $CRUD['DBVERSION'] = 'PostgreSQL server version ' . $CRUD['DBVERSION'][1];
            } catch (PDOException $e) {
                error($e->getMessage());
            }
            break;
        default:
            error('unsupported DBENGINE specified: ' . DBENGINE);
    }
    $CRUD['dbh'] = $dbh;
}
コード例 #2
0
function _init()
{
    global $CRUD;
    $CRUD['TITLE'] = "CRUD";
    $CRUD['SELF'] = $_SERVER["SCRIPT_NAME"];
    // loose "index.php" if nec (regexes are fugly in php. Feh.)
    $CRUD["SELF"] = preg_replace('/([\\/\\\\])index\\.php$/i', '$1', $CRUD["SELF"]);
    foreach (array('BUTTONS', 'HIDDENS', 'MESSAGES', 'ERRORS', 'CONTENT', 'PRECONTENT', 'POSTCONTENT', 'Atitle', 'Aartist', 'Alabel', 'Areleased_day', 'Areleased_month', 'Areleased_year', 'Ttrack_number', 'Ttitle', 'Tduration') as $v) {
        $CRUD[$v] = '';
    }
    switch (DBENGINE) {
        case 'sqlite3':
            try {
                $dbh = new PDO('sqlite:' . DBFILE, 'unused', 'unused');
                $dbh->sqliteCreateFunction('SEC_TO_TIME', 'sec_to_time', 1);
                // custom functions ...
                $dbh->sqliteCreateFunction('TIME_TO_SEC', 'time_to_sec', 1);
                $dbh->sqliteCreateAggregate('SUM_SEC_TO_TIME', 'sum_sec_to_time_step', 'sum_sec_to_time_finalize', 1);
            } catch (PDOException $e) {
                error($e->getMessage());
            }
            break;
        case 'mysql':
            // connect to the database (persistent)
            try {
                $dbh = new PDO('mysql:host=localhost;dbname=' . MYSQLDB, MYSQLUSER, MYSQLPASS, array(PDO::ATTR_PERSISTENT => true));
            } catch (PDOException $e) {
                error($e->getMessage());
            }
            break;
        default:
            error('unsupported DBENGINE specified: ' . DBENGINE);
    }
    $CRUD['dbh'] = $dbh;
}
コード例 #3
0
ファイル: SQLDemo.php プロジェクト: hassanazimi/MySQL
function _init()
{
    global $SID;
    global $db_list;
    $default_db = $db_list[0];
    // initialize display vars
    foreach (array('MESSAGES', 'ERRORS', 'CONTENT', 'SQLfield') as $v) {
        $SID[$v] = '';
    }
    // connect to the database (persistent)
    $database = isset($_REQUEST['select_database']) ? $_REQUEST['select_database'] : $default_db;
    if ($database == '--NONE--') {
        $database = $default_db;
    }
    $SID['utf8'] = FALSE;
    try {
        switch (DBENGINE) {
            case 'sqlite3':
                // don't add the DBDIR to :memory: you'll create a file
                if ($database == ':memory:') {
                    $dbh = new PDO('sqlite::memory:', 'unused', 'unused');
                } else {
                    $dbh = new PDO('sqlite:' . implode('/', array(DBDIR, $database)), 'unused', 'unused');
                }
                $dbh->sqliteCreateFunction('SEC_TO_TIME', 'sec_to_time', 1);
                // custom functions ...
                $dbh->sqliteCreateFunction('TIME_TO_SEC', 'time_to_sec', 1);
                $dbh->sqliteCreateAggregate('SUM_SEC_TO_TIME', 'sum_sec_to_time_step', 'sum_sec_to_time_finalize', 1);
                $dbh->sqliteCreateFunction('REPLACE_REGEX', 'replace_regex', 3);
                $dbh->sqliteCreateAggregate('AVG_LENGTH', 'avg_length_step', 'avg_length_finalize', 1);
                $SID['DBVERSION'] = SQLite3::version();
                $SID['DBVERSION'] = 'SQLite version ' . $SID['DBVERSION']['versionString'];
                $SID['utf8'] = TRUE;
                break;
            case 'pgsql':
                if ($database == '--NONE--') {
                    $database = 'test';
                }
                $dbh = new PDO('pgsql:host=localhost;port=5432;dbname=' . $database, PGSQLUSER, PGSQLPASS, array(PDO::ATTR_PERSISTENT => true));
                $dbh->exec("set client_encoding to 'latin1'");
                $sth = $dbh->query('SELECT VERSION()');
                $SID['DBVERSION'] = explode(' ', $sth->fetchColumn());
                $SID['DBVERSION'] = 'PostgreSQL server version ' . $SID['DBVERSION'][1];
                break;
            case 'mysql':
                if ($database == '--NONE--') {
                    $database = '';
                }
                $dbh = new PDO('mysql:host=localhost;dbname=' . $database, MYSQLUSER, MYSQLPASS, array(PDO::ATTR_PERSISTENT => true));
                $dbh->exec('set character_set_client = utf8');
                $dbh->exec('set character_set_connection = utf8');
                $dbh->exec('set character_set_database = utf8');
                $dbh->exec('set character_set_results = utf8');
                $dbh->exec('set character_set_server = utf8');
                $sth = $dbh->query("SHOW VARIABLES WHERE Variable_name = 'version'");
                $SID['DBVERSION'] = 'MySQL server version ' . $sth->fetchColumn(1);
                $SID['utf8'] = TRUE;
                break;
            default:
                error('unsupported DBENGINE: ' . DBENGINE);
        }
    } catch (PDOException $e) {
        error("Error while constructing PDO object: " . $e->getMessage());
    }
    if ($dbh) {
        // set exception mode for errors (why is this not the default?)
        // this is far more portable for different DB engines than trying to
        // parse error codes
        $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        $SID['dbh'] = $dbh;
    } else {
        exit;
    }
    // try to set the timezone to UTC for mysql
    // ignore error -- TZ support not installed in default win xampp
    if ($dbh && DBENGINE == 'mysql') {
        try {
            $dbh->exec('set time_zone = UTC');
        } catch (PDOException $e) {
            // ignore
        }
    }
    $SID['TITLE'] = "SQL Demo";
    $SID['SELF'] = $_SERVER["SCRIPT_NAME"];
    $SID['DATABASE_SELECT_LIST'] = database_select_list($database);
    // fixup missing common characters from the PHP entity translation table
    // (this is only used for latin1 conversions)
    $SID['xlat'] = get_html_translation_table(HTML_ENTITIES, ENT_NOQUOTES);
    $SID['xlat'][chr(130)] = '‚';
    // Single Low-9 Quotation Mark
    $SID['xlat'][chr(131)] = 'ƒ';
    // Latin Small Letter F With Hook
    $SID['xlat'][chr(132)] = '„';
    // Double Low-9 Quotation Mark
    $SID['xlat'][chr(133)] = '…';
    // Horizontal Ellipsis
    $SID['xlat'][chr(136)] = 'ˆ';
    // Modifier Letter Circumflex Accent
    $SID['xlat'][chr(138)] = 'Š';
    // Latin Capital Letter S With Caron
    $SID['xlat'][chr(139)] = '‹';
    // Single Left-Pointing Angle Quotation Mark
    $SID['xlat'][chr(140)] = 'Œ';
    // Latin Capital Ligature OE
    $SID['xlat'][chr(145)] = '‘';
    // Left Single Quotation Mark
    $SID['xlat'][chr(146)] = '’';
    // Right Single Quotation Mark
    $SID['xlat'][chr(147)] = '“';
    // Left Double Quotation Mark
    $SID['xlat'][chr(148)] = '”';
    // Right Double Quotation Mark
    $SID['xlat'][chr(149)] = '•';
    // Bullet
    $SID['xlat'][chr(150)] = '–';
    // En Dash
    $SID['xlat'][chr(151)] = '—';
    // Em Dash
    $SID['xlat'][chr(152)] = '˜';
    // Small Tilde
    $SID['xlat'][chr(154)] = 'š';
    // Latin Small Letter S With Caron
    $SID['xlat'][chr(155)] = '›';
    // Single Right-Pointing Angle Quotation Mark
    $SID['xlat'][chr(156)] = 'œ';
    // Latin Small Ligature OE
    $SID['xlat'][chr(159)] = 'Ÿ';
    // Latin Capital Letter Y With Diaeresis
    // loose "index.php" if nec (regexes are fugly in php. Feh.)
    $SID["SELF"] = preg_replace('/([\\/\\\\])index\\.php$/i', '$1', $SID["SELF"]);
}
コード例 #4
0
<?php

//create or open database
$dbconn = new PDO("sqlite:/var/www/openmediamanager/sqlite/openmediamanager.sqlite");
function group_concat_step($context, $idx, $string, $separator)
{
    return $context ? $context . $separator . $string : $string;
}
function group_concat_finalize($context)
{
    return $context;
}
$dbconn->sqliteCreateAggregate('group_concat', 'group_concat_step', 'group_concat_finalize', 2);
$applic_config = array();
$sql = "SELECT * FROM config";
$res = $dbconn->query($sql);
while ($row = $res->fetch(PDO::FETCH_ASSOC)) {
    $applic_config['###' . strtoupper($row['config_name']) . '###'] = stripslashes($row['config_value']);
}
$applic_config_default = array();
foreach ($applic_config as $config_name => $config_value) {
    $config_name = str_replace("#", "", $config_name);
    $config_name_exploded = explode("_", $config_name);
    if ($config_name_exploded[0] != "DEFAULT") {
        if (isset($applic_config['###DEFAULT_' . $config_name . '###']) && $applic_config['###' . $config_name . '###'] == "") {
            $applic_config_default['###' . $config_name . '###'] = $applic_config['###DEFAULT_' . $config_name . '###'];
        } else {
            $applic_config_default['###' . $config_name . '###'] = $applic_config['###' . $config_name . '###'];
        }
    }
}
コード例 #5
0
<?php

$pdo = new PDO('sqlite::memory:');
$pdo->sqliteCreateAggregate('foo', 'a', '');
$pdo->sqliteCreateAggregate('foo', 'strlen', '');