コード例 #1
0
ファイル: bootstrap.php プロジェクト: linuxwhy/tiki-1
$api_tiki = 'adodb';
$local_php = __DIR__ . '/local.php';
require_once $local_php;
$style_base = 'skeleton';
// Force autoloading
if (!class_exists('ADOConnection')) {
    die('AdoDb not found.');
}
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
$initializer = new TikiDb_Initializer();
$initializer->setPreferredConnector($api_tiki);
$db = $initializer->getConnection(array('host' => $host_tiki, 'user' => $user_tiki, 'pass' => $pass_tiki, 'dbs' => $dbs_tiki, 'charset' => $client_charset));
if (!$db) {
    die("\nUnable to connect to the database\n\n");
}
TikiDb::set($db);
global $tikilib;
require_once 'lib/tikilib.php';
$tikilib = new TikiLib();
// update db if needed
require_once 'lib/init/initlib.php';
include_once 'installer/installlib.php';
$installer = new Installer();
if (!$installer->tableExists('tiki_preferences')) {
    echo "Installing Tiki database...\n";
    $installer->cleanInstall();
} else {
    if ($installer->requiresUpdate()) {
        echo "Updating Tiki database...\n";
        $installer->update();
    }
コード例 #2
0
ファイル: tiki-installer.php プロジェクト: hurcane/tiki-azure
/**
 * @param $api
 * @param $driver
 * @param $host
 * @param $user
 * @param $pass
 * @param $dbname
 * @param $client_charset
 * @param $dbTiki
 * @return bool|int
 */
function initTikiDB(&$api, &$driver, $host, $user, $pass, $dbname, $client_charset, &$dbTiki)
{
    $initializer = new TikiDb_Initializer();
    $initializer->setPreferredConnector($api_tiki);
    $initializer->setInitializeCallback(function ($db) {
        $db->setServerType($db_tiki);
        $db->setErrorHandler(new InstallerDatabaseErrorHandler());
    });
    global $tikifeedback;
    $dbcon = false;
    try {
        $dbTiki = $initializer->getConnection(array('host' => $host, 'user' => $user, 'pass' => $pass, 'dbs' => $dbname, 'charset' => $client_charset));
        $dbcon = !empty($dbTiki);
    } catch (Exception $e) {
        $tikifeedback[] = array('num' => 1, 'mes' => $e->getMessage());
    }
    // Attempt to create database. This might work if the $user has create database permissions.
    // First check that suggested database name will not cause issues
    $dbname_clean = preg_replace('/[^a-z0-9$_-]/', "", $dbname);
    if ($dbname_clean != $dbname) {
        $tikifeedback[] = array('num' => 1, 'mes' => tra("Some invalid characters were detected in database name. Please use alphanumeric characters or _ or -.", '', false, array($dbname_clean)));
        $attempt_creation = false;
    } else {
        $attempt_creation = true;
    }
    if (!$dbcon && $attempt_creation == true) {
        $sql = "CREATE DATABASE IF NOT EXISTS `{$dbname_clean}` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;";
        $dbTiki->query($sql, $error);
        if (empty($error)) {
            $tikifeedback[] = array('num' => 1, 'mes' => tra("Database `%0` was created.", '', false, array($dbname_clean)));
        } else {
            $tikifeedback[] = array('num' => 1, 'mes' => tra("Database `%0` creation failed. You need to create the database.", '', false, array($dbname_clean)));
        }
        try {
            $dbTiki = $initializer->getConnection(array('host' => $host, 'user' => $user, 'pass' => $pass, 'dbs' => $dbname, 'charset' => $client_charset));
            $dbcon = !empty($dbTiki);
        } catch (Exception $e) {
            $tikifeedback[] = array('num' => 1, 'mes' => $e->getMessage());
        }
    }
    TikiDb::set($dbTiki);
    return $dbcon;
}
コード例 #3
0
    $pdo_options = array();
    $pdo_post_queries = array();
    if (isset($client_charset)) {
        $charset_query = "SET NAMES {$client_charset}";
        if (defined('PDO::MYSQL_ATTR_INIT_COMMAND')) {
            $pdo_options[PDO::MYSQL_ATTR_INIT_COMMAND] = $charset_query;
        } else {
            $pdo_post_queries[] = $charset_query;
        }
        unset($charset_query);
    }
    $dbTiki = new PDO("{$db_tiki}:{$db_hoststring};dbname={$dbs_tiki}", $user_tiki, $pass_tiki, $pdo_options);
    $dbTiki->setAttribute(PDO::ATTR_CASE, PDO::CASE_NATURAL);
    $dbTiki->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
    $dbTiki->setAttribute(PDO::ATTR_ORACLE_NULLS, PDO::NULL_EMPTY_STRING);
    TikiDb::set(new TikiDb_Pdo($dbTiki));
    $tempDb = TikiDb::get();
    if ($api_tiki_forced || isset($dbversion_tiki) && $dbversion_tiki[0] >= 4) {
        $previousApi = $api_tiki;
    } else {
        $previousApi = 'adodb';
    }
    foreach ($pdo_post_queries as $query) {
        $tempDb->query($query);
    }
    unset($tempDb, $pdo_options, $pdo_post_queries);
} catch (PDOException $e) {
    require_once 'lib/init/smarty.php';
    $smarty->assign('msg', $e->getMessage());
    $smarty->assign('where', 'connection');
    echo $smarty->fetch('database-connection-error.tpl');
コード例 #4
0
function initTikiDB(&$api, &$driver, $host, $user, $pass, $dbname, $client_charset, &$dbTiki)
{
    global $tikifeedback;
    $dbcon = false;
    // This section handles the case of adodb (not the preferred case)
    if (isset($api) && $api == 'adodb' || !extension_loaded('pdo')) {
        $api = 'adodb';
        $dbTiki = ADONewConnection($driver);
        $db = new TikiDb_Adodb($dbTiki);
        if (!($dbcon = (bool) @$dbTiki->Connect($host, $user, $pass, $dbname))) {
            $tikifeedback[] = array('num' => 1, 'mes' => $dbTiki->ErrorMsg());
        }
        // Attempt to create database. This might work if the $user has create database permissions.
        // First check that suggested database name will not cause issues
        $dbname_clean = preg_replace('/[^a-z0-9$_-]/', "", $dbname);
        if ($dbname_clean != $dbname) {
            $tikifeedback[] = array('num' => 1, 'mes' => tra("Some invalid characters were detected in database name. Please use alphanumeric characters or _ or -.", '', false, array($dbname_clean)));
            $attempt_creation = false;
        } else {
            $attempt_creation = true;
        }
        if (!$dbcon && $attempt_creation == true) {
            $dbh = ADONewConnection($driver);
            if (@$dbh->Connect($host, $user, $pass)) {
                $sql = "CREATE DATABASE IF NOT EXISTS `{$dbname_clean}` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;";
                $dbcon = $dbh->Execute($sql);
                if ($dbcon) {
                    $tikifeedback[] = array('num' => 1, 'mes' => tra("Database `%0` was created.", '', false, array($dbname_clean)));
                } else {
                    $tikifeedback[] = array('num' => 1, 'mes' => tra("Database `%0` creation failed. You need to create the database.", '', false, array($dbname_clean)));
                }
            } else {
                $tikifeedback[] = array('num' => 1, 'mes' => $dbh->ErrorMsg());
            }
            if ($dbcon) {
                $dbTiki = ADONewConnection($driver);
                $db = new TikiDb_Adodb($dbTiki);
                if (!($dbcon = (bool) @$dbTiki->Connect($host, $user, $pass, $dbname))) {
                    $tikifeedback[] = array('num' => 1, 'mes' => $dbTiki->ErrorMsg());
                }
            }
        }
        // This section handles the case of PDO (preferred case)
    } else {
        $db_hoststring = "host={$host}";
        if ($driver == 'mysqli') {
            $driver = 'mysql';
            if (isset($socket_tiki)) {
                $db_hoststring = "unix_socket={$socket_tiki}";
            }
        }
        try {
            $dbTiki = new PDO("{$driver}:{$db_hoststring};dbname={$dbname}", $user, $pass);
            $db = new TikiDb_Pdo($dbTiki);
            $dbcon = true;
        } catch (PDOException $e) {
            $dbcon = false;
            $tikifeedback[] = array('num' => 1, 'mes' => $e->getMessage());
        }
        // Attempt to create database. This might work if the $user has create database permissions.
        // First check that suggested database name will not cause issues
        $dbname_clean = preg_replace('/[^a-z0-9$_-]/', "", $dbname);
        if ($dbname_clean != $dbname) {
            $tikifeedback[] = array('num' => 1, 'mes' => tra("Some invalid characters were detected in database name. Please use alphanumeric characters or _ or -.", '', false, array($dbname_clean)));
            $attempt_creation = false;
        } else {
            $attempt_creation = true;
        }
        if (!$dbcon && $attempt_creation == true) {
            try {
                $dbh = new PDO("{$driver}:{$db_hoststring}", $user, $pass);
                $sql = "CREATE DATABASE IF NOT EXISTS `{$dbname_clean}` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci;";
                $dbcon = $dbh->exec($sql);
                if ($dbcon) {
                    $tikifeedback[] = array('num' => 1, 'mes' => tra("Database `%0` was created.", '', false, array($dbname_clean)));
                } else {
                    $tikifeedback[] = array('num' => 1, 'mes' => tra("Database `%0` creation failed. You need to create the database.", '', false, array($dbname_clean)));
                }
            } catch (PDOException $e) {
                $dbcon = false;
                $tikifeedback[] = array('num' => 1, 'mes' => $e->getMessage());
            }
            if ($dbcon) {
                try {
                    $dbTiki = new PDO("{$driver}:{$db_hoststring};dbname={$dbname}", $user, $pass);
                    $db = new TikiDb_Pdo($dbTiki);
                } catch (PDOException $e) {
                    $dbcon = false;
                    $tikifeedback[] = array('num' => 1, 'mes' => $e->getMessage());
                }
            }
        }
    }
    if ($dbcon) {
        $db->setErrorHandler(new InstallerDatabaseErrorHandler());
        if (!empty($client_charset)) {
            $db->query("SET CHARACTER SET {$client_charset}");
        }
        TikiDb::set($db);
    }
    return $dbcon;
}
コード例 #5
0
ファイル: bootstrap.php プロジェクト: hurcane/tiki-azure
$local_php = dirname(__FILE__) . '/local.php';
require_once $local_php;
$style_base = 'skeleton';
// Force autoloading
if (!class_exists('ADOConnection')) {
    die('AdoDb not found.');
}
$ADODB_FETCH_MODE = ADODB_FETCH_ASSOC;
// for now the unit test suite only works with adodb
// using pdo generate an error when phpunit tries to serialize the globals variables
// since it is not possible to serialize a PDO object
$dbTiki = ADONewConnection($db_tiki);
if (!@$dbTiki->Connect($host_tiki, $user_tiki, $pass_tiki, $dbs_tiki)) {
    die("\nUnable to connect to the database\n\n");
}
TikiDb::set(new TikiDb_Adodb($dbTiki));
global $tikilib;
require_once 'lib/tikilib.php';
$tikilib = new TikiLib();
// update db if needed
require_once 'lib/init/initlib.php';
include_once 'installer/installlib.php';
$installer = new Installer();
if (!$installer->tableExists('tiki_preferences')) {
    echo "Installing Tiki database...\n";
    $installer->cleanInstall();
} else {
    if ($installer->requiresUpdate()) {
        echo "Updating Tiki database...\n";
        $installer->update();
    }