function init_database_static() { connect_to_db_or_die(); global $dbxlink; if (!isInnoDBSupported()) { echo 'InnoDB test failed! Please configure MySQL server properly and retry.'; return FALSE; } $result = $dbxlink->query('show tables'); $tables = $result->fetchAll(PDO::FETCH_NUM); $result->closeCursor(); unset($result); if (count($tables)) { echo 'Your database is already holding ' . count($tables); echo ' tables, so I will stop here and let you check it yourself.<br>'; echo 'There is some important data there probably.<br>'; return FALSE; } echo 'Initializing the database...<br>'; echo '<table border=1>'; echo "<tr><th>section</th><th>queries</th><th>errors</th></tr>"; $errlist = array(); foreach (array('structure', 'dictbase') as $part) { echo "<tr><td>{$part}</td>"; $nq = $nerrs = 0; foreach (preg_split("/;\\s*\n/", get_pseudo_file($part)) as $query) { $query = trim($query); if (empty($query) or '--' == substr($query, 0, 2)) { continue; } $nq++; if ($dbxlink->exec($query) === FALSE) { $nerrs++; $errlist[] = $query; } } echo "<td>{$nq}</td><td>{$nerrs}</td></tr>\n"; } // (re)load dictionary by pure PHP means w/o any external file echo "<tr><td>dictionary</td>"; $nq = $nerrs = 0; $dictq = array(); foreach (reloadDictionary() as $query) { $nq++; if ($dbxlink->exec($query) === FALSE) { $nerrs++; $errlist[] = $query; } } echo "<td>{$nq}</td><td>{$nerrs}</td></tr>\n"; echo '</table>'; if (count($errlist)) { echo '<pre>The following queries failed:\\n'; foreach ($errlist as $q) { echo "{$q}\n\n"; } echo '</pre>'; return FALSE; } return TRUE; }
function init_database_static() { connect_to_db_or_die(); global $dbxlink; if (!isInnoDBSupported()) { echo 'InnoDB test failed! Please configure MySQL server properly and retry.'; return FALSE; } $result = $dbxlink->query('show tables'); $tables = $result->fetchAll(PDO::FETCH_NUM); $result->closeCursor(); unset($result); if (count($tables)) { echo 'Your database is already holding ' . count($tables); echo ' tables, so I will stop here and let you check it yourself.<br>'; echo 'There is some important data there probably.<br>'; return FALSE; } echo 'Initializing the database...<br>'; echo '<table border=1>'; echo "<tr><th>section</th><th>queries</th><th>errors</th></tr>"; $failures = array(); foreach (array('structure', 'dictbase') as $part) { echo "<tr><td>{$part}</td>"; $nq = $nerrs = 0; foreach (get_pseudo_file($part) as $q) { if (empty($q)) { continue; } try { $result = $dbxlink->query($q); $nq++; } catch (PDOException $e) { $nerrs++; $errorInfo = $dbxlink->errorInfo(); $failures[] = array($q, $errorInfo[2]); } } echo "<td>{$nq}</td><td>{$nerrs}</td></tr>\n"; } if (!count($failures)) { echo "<strong><font color=green>done</font></strong>"; } else { echo "<strong><font color=red>The following queries failed:</font></strong><br><pre>"; foreach ($failures as $f) { list($q, $i) = $f; echo "{$q} -- {$i}\n"; } } // (re)load dictionary by pure PHP means w/o any external file echo "<tr><td>dictionary</td>"; $nq = $nerrs = 0; $dictq = array(); foreach (reloadDictionary() as $query) { $nq++; if ($dbxlink->exec($query) === FALSE) { $nerrs++; $errlist[] = $query; } } echo "<td>{$nq}</td><td>{$nerrs}</td></tr>\n"; echo '</table>'; if (isset($errlist) && count($errlist)) { echo '<pre>The following queries failed:\\n'; foreach ($errlist as $q) { echo "{$q}\n\n"; } echo '</pre>'; return FALSE; } return TRUE; }