Example #1
0
function PopulateSQLData($NewSQL = false, $Demo = false, $db, $DBType, $NewDB = false)
{
    if ($NewSQL) {
        if ($DBType == 'mysqli') {
            //if the mysql db type is mysqli
            mysqli_select_db($db, $NewDB);
            //currently there is no 'USE' statements in sql file, no bother to remove them
            $sql = 'SET names UTF8;';
            $sql .= file_get_contents($NewSQL);
            if (!$sql) {
                die(_('Failed to open the new sql file'));
            }
            $result = mysqli_multi_query($db, $sql);
            if (!$result) {
                prnMsg(_('Failed to populate the database' . ' ' . $NewDB . ' and the error is') . ' ' . mysqli_error($db), 'error');
            }
            //now clear the result otherwise the next operation will failed with commands out of sync
            //Since the mysqli_multi_query() return boolean value, we must retrieve the query result set
            //via mysqli_store_result or mysqli_use_result
            //mysqli_store_result return an buffered object or false if failed or no such object such as result of INSERT
            //so if it's false no bother to free them
            do {
                if ($result = mysqli_store_result($db)) {
                    mysqli_free_result($result);
                }
            } while (mysqli_more_results($db) ? mysqli_next_result($db) : false);
            //} while (mysqli_next_result($db));
        } else {
            PopulateSQLDataBySQL($NewSQL, $db, $DBType, $NewDB);
        }
    }
    if ($Demo) {
        if ($DBType == 'mysqli') {
            mysqli_select_db($db, $NewDB);
        } else {
            mysql_select_db($NewDB, $db);
        }
        PopulateSQLDataBySQL($Demo, $db, $DBType, false, $NewDB);
        //we can let users wait instead of changing the my.cnf file
        //It is a non affordable challenge for them since wamp set the max_allowed_packet 1M
        //and weberpdemo.sql is 1.4M so at least it cannot install in wamp
        //so we not use the multi query here
        /*	$SQLFile = fopen($Demo);
        
        						$sql = file_get_contents($Demo);
        						if(!$sql){
        							die(_('Failed to open the demo sql file'));
        						}
        
        						$result = mysqli_multi_query($db,$sql);
        
        						if(!$result){
        							prnMsg(_('Failed to populate the database'.' '.$NewDB.' and the error is').' '.mysqli_error($db),'error');
        						}
        						//clear the bufferred result
        						do {
        							if($result = mysqli_store_result($db)){
        								mysqli_free_result($result);
        							}
        						} while (mysqli_more_results($db)?mysqli_next_result($db):false); */
        /*	}else{
        						mysqli_select_db($db,$NewDB);
        						PopulateSQLDataBySQL($Demo,$db,$DBType,false,$NewDB);
        			}*/
    }
}
Example #2
0
        echo '<div class="error">' . $Message . '</div>';
    }
    exit;
}
InsertRecord('www_users', array('userid'), array('admin'), array('userid', 'password', 'realname', 'email', 'displayrecordsmax', 'fullaccess', 'cancreatetender', 'modulesallowed', 'blocked', 'theme', 'language', 'pdflanguage', 'fontsize'), array($_SESSION['Installer']['AdminAccount'], sha1($_SESSION['Installer']['KwaMojaPassword']), $_SESSION['Installer']['AdminAccount'], $_SESSION['Installer']['Email'], 50, 1, 1, '1,1,1,1,1,1,1,1,1,1,1,1,', 0, 'aguapop', $_SESSION['Installer']['Language'], 0, 0), $db);
/* Now we uploade the chosen chart of accounts */
if (!isset($_POST['Demo'])) {
    $sql = "SET foreign_key_checks=0";
    $result = executeSQL($sql, $db, False);
    include $PathPrefix . 'install/coa/' . $_SESSION['Installer']['CoA'];
    echo '<div class="success">' . _('Your chosen chart of accounts has been uploaded') . '</div>';
    ob_flush();
    /* Create the admin user */
} else {
    echo '<legend>' . _('Populating the database with demo data.') . '</legend>';
    PopulateSQLDataBySQL($PathPrefix . 'sql/demodata/data.sql', $db, $DBType, false, $_SESSION['Installer']['Database']);
}
ChangeConfigValue('VersionNumber', '14.02', $db);
function HighestFileName($PathPrefix)
{
    $files = glob($PathPrefix . 'sql/install/*.php');
    natsort($files);
    return basename(array_pop($files), ".php");
}
function executeSQL($sql, $db, $TrapErrors = False)
{
    global $SQLFile;
    /* Run an sql statement and return an error code */
    if (!isset($SQLFile)) {
        DB_IgnoreForeignKeys($db);
        $result = DB_query($sql, $db, '', '', false, $TrapErrors);