예제 #1
0
function db_connection($identifier = 'default')
{
    global $synchrotron_dbs;
    $db = $synchrotron_dbs[$identifier];
    if (!$db) {
        $db = SynchrotronDBConnection::Copy($identifier, $synchrotron_dbs['default']);
    }
    if ($db instanceof SynchrotronDBConnection) {
        if (!$db->resource) {
            if ($db->persistent) {
                $db->resource = pg_pconnect($db->connectString(), PGSQL_CONNECT_FORCE_NEW);
            } else {
                $db->resource = pg_connect($db->connectString(), PGSQL_CONNECT_FORCE_NEW);
            }
            if (!$db->resource) {
                global $db_debug;
                if ($db_debug) {
                    print "Could not connect to PostgreSQL\n";
                    exit(0);
                }
            }
        }
        return $db->resource;
    }
    return false;
}
예제 #2
0
파일: mysql.php 프로젝트: KDE/synchrotron
function db_connection($identifier = 'default')
{
    global $synchrotron_dbs;
    $db = $synchrotron_dbs[$identifier];
    if (!$db) {
        $db = SynchrotronDBConnection::Copy($identifier, $synchrotron_dbs['default']);
    }
    if ($db instanceof SynchrotronDBConnection) {
        if (!$db->resource) {
            if ($db->persistent) {
                $db->resource = mysql_pconnect($db->db_host, $db->db_username, $db->db_password);
            } else {
                $db->resource = mysql_connect($db->db_host, $db->db_username, $db->db_password);
            }
            mysql_query("USE {$db->db_name};", $db->resource);
        }
        return $db->resource;
    }
    return false;
}