function installdb()
{
    global $prefix, $db_name;
    mysql_select_db($db_name) or die("ERROR: " . mysql_error());
    $sql_query = addslashes(fread(fopen("phpBazar.sql", "r"), filesize("phpBazar.sql")));
    $pieces = split_sql($sql_query);
    if (count($pieces) == 1 && !empty($pieces[0])) {
        echo "Error !!!";
    }
    for ($i = 0; $i < count($pieces); $i++) {
        $pieces[$i] = stripslashes(trim($pieces[$i]));
        if (!empty($pieces[$i]) && $pieces[$i] != "#") {
            $pieces[$i] = str_replace("IF EXISTS ", "IF EXISTS " . $prefix, $pieces[$i]);
            $pieces[$i] = str_replace("CREATE TABLE ", "CREATE TABLE " . $prefix, $pieces[$i]);
            $pieces[$i] = str_replace("INSERT INTO ", "INSERT INTO " . $prefix, $pieces[$i]);
            $result = mysql_query($pieces[$i]);
            if (!$result) {
                echo "Database: [{$db_name}] - MYSQL-ERROR: " . mysql_error() . "<br>Command: " . stripslashes($pieces[$i]) . "<br>";
            } else {
                echo "Database: [{$db_name}] - mySQL-command: <b>OK!</b><br>";
            }
        }
    }
    echo "<br><b>Logix Classifieds Tables installed, Ready ...</b>";
}
/**
 * Following two functions populate_database() and split_sql() were taken from Joomla!
 * From the file /installation/installer/helper.php of release 1.5.6
 */
function populate_database($sqlfile)
{
    if (!($buffer = file_get_contents($sqlfile))) {
        return -1;
    }
    $queries = split_sql($buffer);
    foreach ($queries as $query) {
        $query = trim($query);
        if ($query != '' && $query[0] != '#') {
            mysql_query($query);
            if (mysql_error()) {
                die(mysql_error());
            }
        }
    }
}
示例#3
0
function crear_db($DBname, $sqlfile = 'MaxCodecaRev.sql')
{
    mysql_select_db($DBname);
    $mqr = @get_magic_quotes_runtime();
    @set_magic_quotes_runtime(0);
    $query = fread(fopen("./" . $sqlfile, "r"), filesize("./" . $sqlfile));
    @set_magic_quotes_runtime($mqr);
    $pieces = split_sql($query);
    $errors = array();
    for ($i = 0; $i < count($pieces); $i++) {
        $pieces[$i] = trim($pieces[$i]);
        if (!empty($pieces[$i]) && $pieces[$i] != "#") {
            if (!($result = mysql_query($pieces[$i]))) {
                $errors[] = array(mysql_error(), $pieces[$i]);
            }
        }
    }
}
示例#4
0
function updateConfig($module, $newsql)
{
    global $db, $set;
    //Aktuelle Werte auslesen
    $olddata = $db->fetch("SELECT varname, value FROM " . PRE . "_config WHERE module='" . addslashes($module) . "'");
    //Alte Einträge entfernen und neue einfügen
    $db->query("DELETE FROM " . PRE . "_config WHERE module='" . addslashes($module) . "'");
    $queries = split_sql($newsql);
    foreach ($queries as $query) {
        $db->query($query);
    }
    //Aktuelle Werte übernehmen
    if (count($olddata)) {
        foreach ($olddata as $res) {
            $db->query("\n\t\t\t\tUPDATE " . PRE . "_config\n\t\t\t\tSET value='" . addslashes($res['value']) . "'\n\t\t\t\tWHERE module='" . addslashes($module) . "' AND varname='" . addslashes($res['varname']) . "'\n\t\t\t");
        }
    }
}
示例#5
0
function populate_db(&$database, $sqlfile = 'creermonjeu.sql')
{
    global $errors;
    $mqr = @get_magic_quotes_runtime();
    @set_magic_quotes_runtime(0);
    $query = fread(fopen('sql/' . $sqlfile, 'r'), filesize('sql/' . $sqlfile));
    @set_magic_quotes_runtime($mqr);
    $pieces = split_sql($query);
    for ($i = 0; $i < count($pieces); $i++) {
        $pieces[$i] = trim($pieces[$i]);
        if (!empty($pieces[$i]) && $pieces[$i] != "#") {
            $database->setQuery($pieces[$i]);
            if (!$database->query()) {
                $errors[] = array($database->getErrorMsg(), $pieces[$i]);
            }
        }
    }
}
示例#6
0
/**
 * @param object
 * @param string File name
 */
function populate_db($database, $sqlfile='db_sistem.sql',$sistem=1) {
	global $errors;

	$mqr = @get_magic_quotes_runtime();
	@set_magic_quotes_runtime(0);
        if ($sistem)
            $sqlfile = 'sql/' . $sqlfile;
	$query = fread( fopen($sqlfile, 'r' ), filesize($sqlfile) );
	@set_magic_quotes_runtime($mqr);
	$pieces  = split_sql($query);

	for ($i=0; $i<count($pieces); $i++) {
		$pieces[$i] = trim($pieces[$i]);
		if(!empty($pieces[$i]) && $pieces[$i] != "#") {
			if (!mysql_query($pieces[$i],$database)) 
                $errors[] = mysql_error($database); 
		}
	}
}
function populate_db($DBname, $sqlfile, $host, $user, $password)
{
    $link = mysql_connect($host, $user, $password);
    mysql_select_db($DBname, $link);
    $mqr = @get_magic_quotes_runtime();
    @set_magic_quotes_runtime(0);
    $query = fread(fopen("includes/" . $sqlfile, "r"), filesize("includes/" . $sqlfile));
    @set_magic_quotes_runtime($mqr);
    $pieces = split_sql($query);
    $errors = array();
    for ($i = 0; $i < count($pieces); $i++) {
        $pieces[$i] = trim($pieces[$i]);
        if (!empty($pieces[$i]) && $pieces[$i] != "#") {
            if (!($result = mysql_query($pieces[$i]))) {
                $errors[] = array(mysql_error(), $pieces[$i]);
            }
        }
    }
}
示例#8
0
            //Zu 1.0.2
            $mysql = "\n\t\t\t\tALTER TABLE `apx_links` ADD `broken` INT( 11 ) UNSIGNED NOT NULL AFTER `endtime` ;\n\t\t\t";
            $queries = split_sql($mysql);
            foreach ($queries as $query) {
                $db->query($query);
            }
        case 102:
            //Zu 1.1.0
            //Indizes entfernen
            clearIndices(PRE . '_links');
            clearIndices(PRE . '_links_cat');
            //Tabellenformat ändern
            convertRecursiveTable(PRE . '_links_cat');
            //config Update
            updateConfig('links', "\n\t\t\t\tINSERT INTO `apx_config` (`module`, `varname`, `type`, `addnl`, `value`, `tab`, `lastchange`, `ord`) VALUES\n\t\t\t\t('links', 'epp', 'int', '', '20', 'VIEW', 1249981968, 1000),\n\t\t\t\t('links', 'searchepp', 'string', '', '20', 'VIEW', 1249981881, 2000),\n\t\t\t\t('links', 'catonly', 'switch', '', '1', 'VIEW', 1249981968, 3000),\n\t\t\t\t('links', 'sortby', 'select', 'a:2:{i:1;s:7:\"{TITLE}\";i:2;s:6:\"{DATE}\";}', '1', 'VIEW', 1249981968, 4000),\n\t\t\t\t('links', 'new', 'int', '', '3', 'VIEW', 1249981968, 5000),\n\t\t\t\t\n\t\t\t\t('links', 'searchable', 'switch', '', '1', 'OPTIONS', 1249981968, 1000),\n\t\t\t\t('links', 'coms', 'switch', '', '1', 'OPTIONS', 1249981968, 2000),\n\t\t\t\t('links', 'ratings', 'switch', '', '1', 'OPTIONS', 1249981968, 3000),\n\t\t\t\t('links', 'captcha', 'switch', '', '1', 'OPTIONS', 1249981968, 4000),\n\t\t\t\t('links', 'spamprot', 'int', '', '1', 'OPTIONS', 1249981968, 5000),\n\t\t\t\t('links', 'mailonnew', 'string', '', '', 'OPTIONS', 1249981968, 6000),\n\t\t\t\t('links', 'mailonbroken', 'string', '', '', 'OPTIONS', 1249981968, 7000),\n\t\t\t\t\n\t\t\t\t('links', 'linkpic_width', 'int', '', '120', 'IMAGES', 1249981968, 1000),\n\t\t\t\t('links', 'linkpic_height', 'int', '', '120', 'IMAGES', 1249981968, 2000),\n\t\t\t\t('links', 'linkpic_popup', 'switch', '', '1', 'IMAGES', 1249981968, 3000),\n\t\t\t\t('links', 'linkpic_popup_width', 'int', '', '640', 'IMAGES', 1249981968, 4000),\n\t\t\t\t('links', 'linkpic_popup_height', 'int', '', '480', 'IMAGES', 1249981968, 5000),\n\t\t\t\t('links', 'linkpic_quality', 'switch', '', '1', 'IMAGES', 1249981968, 6000);\n\t\t\t");
            $mysql = "\n\t\t\t\tCREATE TABLE `apx_links_tags` (\n\t\t\t\t\t`id` INT( 11 ) UNSIGNED NOT NULL ,\n\t\t\t\t\t`tagid` INT( 11 ) UNSIGNED NOT NULL ,\n\t\t\t\t\tPRIMARY KEY ( `id` , `tagid` )\n\t\t\t\t) ENGINE=MyISAM;\n\t\t\t\t\n\t\t\t\tALTER TABLE `apx_links` ADD `restricted` TINYINT( 1 ) UNSIGNED NOT NULL AFTER `allowrating` ;\n\t\t\t\t\n\t\t\t\tALTER TABLE `apx_links` ADD INDEX ( `catid` ) ;\n\t\t\t\tALTER TABLE `apx_links` ADD INDEX ( `userid` ) ;\n\t\t\t\tALTER TABLE `apx_links` ADD INDEX ( `starttime` , `endtime` ) ;\n\t\t\t\tALTER TABLE `apx_links_cat` ADD INDEX ( `parents` ) ;\n\t\t\t";
            $queries = split_sql($mysql);
            foreach ($queries as $query) {
                $db->query($query);
            }
            //Tags erzeugen
            transformKeywords(PRE . '_links', PRE . '_links_tags');
        case 110:
            //Zu 1.1.1
            $mysql = "\n\t\t\t\tALTER TABLE `apx_links` ADD `meta_description` TEXT NOT NULL AFTER `text` ;\n\t\t\t";
            $queries = split_sql($mysql);
            foreach ($queries as $query) {
                $db->query($query);
            }
    }
}
示例#9
0
function populate_db($DBname, $DBPrefix, $sqlfile = 'dbsetup.sql')
{
    global $errors;
    mysql_select_db($DBname);
    $mqr = @get_magic_quotes_runtime();
    @set_magic_quotes_runtime(0);
    $query = fread(fopen("sql/" . $sqlfile, "r"), filesize("sql/" . $sqlfile));
    @set_magic_quotes_runtime($mqr);
    $pieces = split_sql($query);
    for ($i = 0; $i < count($pieces); $i++) {
        $pieces[$i] = trim($pieces[$i]);
        if (!empty($pieces[$i]) && $pieces[$i] != "#") {
            $pieces[$i] = str_replace("#__", $DBPrefix, $pieces[$i]);
            if (!($result = mysql_query($pieces[$i]))) {
                $errors[] = array(mysql_error(), $pieces[$i]);
            }
        }
    }
}
function populate_db($db, $sqlfile = 'administrator/backups/database-sql.sql')
{
    global $errors, $_CONFIG;
    if ($_REQUEST['use_mysqldump'] == 1) {
        echo shell_exec($_REQUEST['mysqldump_path'] . " -u " . $_REQUEST[mysql_username] . " -p" . $_REQUEST[mysql_pass] . " -h " . $_REQUEST[mysql_server] . " " . $_REQUEST[mysql_db] . " < " . $sqlfile);
        return;
    }
    $mqr = @get_magic_quotes_runtime();
    @set_magic_quotes_runtime(0);
    @chmod($sqlfile, 0777);
    $query = fread(fopen($sqlfile, 'r'), filesize($sqlfile));
    @set_magic_quotes_runtime($mqr);
    $pieces = split_sql($query);
    for ($i = 0; $i < count($pieces); $i++) {
        $pieces[$i] = trim($pieces[$i]);
        $tmp = explode("DEFAULT CHARSET", $pieces[$i]);
        $pieces[$i] = $tmp[0] . ";";
        if (!empty($pieces[$i]) && $pieces[$i] != "#") {
            if (!$_CONFIG['mysqli']->query($pieces[$i], $db)) {
                $errors[] = "\n\n##Mysql Query: \n########\n" . $pieces[$i] . "\n########\n##Error message: " . $_CONFIG['mysqli']->error;
            }
        }
    }
    return $errors;
}
function populate_mysql_db($sql)
{
    $sql = split_sql($sql, "exec_sql");
}
示例#12
0
 $con = pg_connect("host={$dbip} dbname={$dbname} user={$usr} password={$pass} connect_timeout=3");
 if (pg_last_error()) {
     throw new Exception('When trying to connect to POSTGRES database: <br/>' . pg_last_error());
 }
 $response = array();
 foreach ($sqls as $name => $sql) {
     // for every sequel in the hash
     $sql = trim($sql);
     if (!preg_match("/.*LIMIT\\s+\\d+\\s*;?\$/i", $sql)) {
         //throw new Exception("No trailing LIMIT-clause found for serie '$name'...<br/>SQL: '$sql'<br/>Example: add 'LIMIT 1000' at the end...");
     }
     $sql = preg_replace('/\\s*?--\\s*?.*/', '', $sql);
     // remove comments
     $sql = str_replace(array("\n", "\t"), '', $sql);
     // remove newlines en tabs
     $queries = split_sql($sql);
     $nested = 0;
     foreach ($queries as $query) {
         if (strlen(trim($query)) > 0) {
             $escaped_query = $query;
             //pg_escape_string($con, $query);
             $result = pg_query($con, $query);
             $nested_suffix = $nested == 0 ? "" : "_" . $nested;
             if (pg_last_error()) {
                 throw new Exception('When executing POSTGRES query: <br/>' . pg_last_error() . '<br/><br/>Make sure you doublequote your tablename, and check case sensitivity.');
             }
             $resultset = array();
             while ($row = pg_fetch_row($result)) {
                 array_push($resultset, array($row[0], $row[1]));
             }
             if (count($resultset) != 0) {
示例#13
0
/**
 * install_insert_db
 *
 * Inserts the database using the values from Config.
 */
function install_insert_db($db_user = null, $db_pass = null, $create_db = true, $overwrite = false, $create_tables = true)
{
    $database = AmpConfig::get('database_name');
    // Make sure that the database name is valid
    preg_match('/([^\\d\\w\\_\\-])/', $database, $matches);
    if (count($matches)) {
        Error::add('general', T_('Error: Invalid database name.'));
        return false;
    }
    if (!Dba::check_database()) {
        Error::add('general', sprintf(T_('Error: Unable to make database connection: %s'), Dba::error()));
        return false;
    }
    $db_exists = Dba::read('SHOW TABLES');
    if ($db_exists && $create_db) {
        if ($overwrite) {
            Dba::write('DROP DATABASE `' . $database . '`');
        } else {
            Error::add('general', T_('Error: Database already exists and overwrite not checked'));
            return false;
        }
    }
    if ($create_db) {
        if (!Dba::write('CREATE DATABASE `' . $database . '`')) {
            Error::add('general', sprintf(T_('Error: Unable to create database: %s'), Dba::error()));
            return false;
        }
    }
    Dba::disconnect();
    // Check to see if we should create a user here
    if (strlen($db_user) && strlen($db_pass)) {
        $db_host = AmpConfig::get('database_hostname');
        $sql = 'GRANT ALL PRIVILEGES ON `' . Dba::escape($database) . '`.* TO ' . "'" . Dba::escape($db_user) . "'";
        if ($db_host == 'localhost' || strpos($db_host, '/') === 0) {
            $sql .= "@'localhost'";
        }
        $sql .= "IDENTIFIED BY '" . Dba::escape($db_pass) . "' WITH GRANT OPTION";
        if (!Dba::write($sql)) {
            Error::add('general', sprintf(T_('Error: Unable to create user %1$s with permissions to %2$s on %3$s: %4$s'), $db_user, $database, $db_host, Dba::error()));
            return false;
        }
    }
    // end if we are creating a user
    if ($create_tables) {
        $sql_file = AmpConfig::get('prefix') . '/sql/ampache.sql';
        $query = fread(fopen($sql_file, 'r'), filesize($sql_file));
        $pieces = split_sql($query);
        $errors = array();
        for ($i = 0; $i < count($pieces); $i++) {
            $pieces[$i] = trim($pieces[$i]);
            if (!empty($pieces[$i]) && $pieces[$i] != '#') {
                if (!($result = Dba::write($pieces[$i]))) {
                    $errors[] = array(Dba::error(), $pieces[$i]);
                }
            }
        }
    }
    if ($create_db) {
        $sql = 'ALTER DATABASE `' . $database . '` DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci';
        Dba::write($sql);
    }
    // If they've picked something other than English update default preferences
    if (AmpConfig::get('lang') != 'en_US') {
        // FIXME: 31? I hate magic.
        $sql = 'UPDATE `preference` SET `value`= ? WHERE `id` = 31';
        Dba::write($sql, array(AmpConfig::get('lang')));
        $sql = 'UPDATE `user_preference` SET `value` = ? WHERE `preference` = 31';
        Dba::write($sql, array(AmpConfig::get('lang')));
    }
    return true;
}
示例#14
0
    return $ret;
}
// Definicion de variables para almacenar resultado
$estado_final = "0";
$accion = "";
include_once "dev_tools/tests/t_bdconfig.php";
include_once "core/conexiones.php";
include_once "core/comunes.php";
//PASO 1: Agrega las tablas y ejecuta consultas iniciales sobre la base de datos
$total_ejecutadas = 0;
//Abre el archivo con los queries dependiendo del motor
$RutaScriptSQL = "ins/sql/practico." . $MotorBD;
$archivo_consultas = fopen($RutaScriptSQL, "r");
$total_consultas = fread($archivo_consultas, filesize($RutaScriptSQL));
fclose($archivo_consultas);
$arreglo_consultas = split_sql($total_consultas);
foreach ($arreglo_consultas as $consulta) {
    try {
        //Ejecuta el query
        $consulta_enviar = $ConexionPDO->prepare($consulta);
        $consulta_enviar->execute();
        $total_ejecutadas++;
    } catch (PDOException $ErrorPDO) {
        echo "SQL: " . $consulta . " ==>> " . $ErrorPDO->getMessage();
        $hay_error = 1;
    }
}
//PASO 2: Verifica las tablas creadas en la base de datos
$resultado = consultar_tablas();
$total_tablas = 0;
while ($registro = $resultado->fetch()) {
示例#15
0
/**
 * @param object
 * @param string File name
 */
function populate_db(&$database, $sqlfile = 'nuke.sql')
{
    global $errors;
    $query = fread(fopen('sql/' . $sqlfile, 'r'), filesize('sql/' . $sqlfile));
    $pieces = split_sql($query);
    for ($i = 0; $i < count($pieces); $i++) {
        $pieces[$i] = trim($pieces[$i]);
        if (!empty($pieces[$i]) && $pieces[$i] != "#") {
            $database->setQuery($pieces[$i]);
            if (!$database->query()) {
                $errors[] = array($database->getErrorMsg(), $pieces[$i]);
            }
        }
    }
}
示例#16
0
         if (!empty($pieces[$i]) && $pieces[$i] != "#") {
             $db->query($pieces[$i]);
             $numtables++;
         }
     }
     echo '<b><span style="color:#00cc00">Таблицы успешно импортированы</span></b><br />';
     echo 'Всего загружено таблиц: ' . $numtables . '<br /><br />';
 } catch (PDOException $e) {
     $errortables = 1;
     echo '<b><span style="color:#ff0000">Ошибка! Не удалось импортировать таблицы в БД!</span></b><br />';
     echo 'Код ошибки: ' . $e->getMessage() . '<br /><br />';
 }
 // ------------------------------------------//
 try {
     $query = file_get_contents('sql/data.sql');
     $pieces = split_sql($query);
     $numtables = 0;
     for ($i = 0; $i < count($pieces); $i++) {
         $pieces[$i] = trim($pieces[$i]);
         if (!empty($pieces[$i]) && $pieces[$i] != "#") {
             $db->query($pieces[$i]);
             $numtables++;
         }
     }
     echo '<b><span style="color:#00cc00">Данные успешно импортированы</span></b><br />';
     echo 'Всего загружено данных: ' . $numtables . '<br /><br />';
 } catch (PDOException $e) {
     $errortables = 1;
     echo '<b><span style="color:#ff0000">Ошибка! Не удалось загрузить данные в БД!</span></b><br />';
     echo 'Код ошибки: ' . $e->getMessage() . '<br /><br />';
 }