Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><a href="http://en.wikipedia.org/wiki/KISS_principle" rel="nofollow noreferrer">KISS principle</a>: just use phpMyAdmin? It's almost certainly installed. If it's not, <a href="http://phpmyadmin.net/" rel="nofollow noreferrer">install it</a>.</p> <p>Its import capability is magnificent. If your database is by any chance too big, gzip it. If it's still to big, try splitting it up in a few pieces. I doubt you need to transfer it as a single big transaction. Do you?</p> <hr> <p>After the explanation in first comment, well, here goes. This is my very simplistic script which does what you want. Except it doesn't take a look at the separators: one query == one line.</p> <pre><code>&lt;link rel="stylesheet" href="style/contents.css"/&gt; &lt;? function timesanitize($v) { if ($v &gt; 0) return round($v, 4); else return 0; } $startmt = microtime(); include_once 'include/db.php'; $f = fopen("db.sql","r"); echo dbGetEngine() . "&lt;br&gt;"; echo "&lt;ul&gt;"; do { $l = rtrim(fgets($f)); if (strlen($l) == 0) continue; if (substr($l, 0, 1) == '#') continue; $l = str_replace( array("\\n"), array("\n"), $l); if (dbGetEngine() == "pgsql") $l = str_replace( array("IF NOT EXISTS", "LONGBLOB"), array("", "TEXT"), $l); try { echo "&lt;li&gt;".nl2br(htmlspecialchars($l)); $mt = microtime(); $db-&gt;query($l); echo "&lt;ul&gt;&lt;li&gt;ok - " . timesanitize(microtime() - $mt) . "&lt;/ul&gt;"; } catch (PDOException $e) { echo "&lt;ul&gt;&lt;li&gt;".$e-&gt;getMessage() . "&lt;/ul&gt;"; } } while (!feof($f)); fclose($f); echo 'total: ' . timesanitize(microtime() - $startmt); ?&gt; </code></pre> <p>It also outputs a small statistic of how long each query took. It's based around PDO; I believe PDO was introduced in PHP5.1 or PHP5.2. I think it should be trivial to modify it to work directly with <code>mysql_*()</code> functions, if for some reason you prefer that. </p> <p>And once again: yes, I know it sucks. But as long as it Works For Me (tm), and possibly You... :-)</p> <hr> <p>To complete the code, here are <code>include/db.php</code> and a sample <code>include/config.php</code>:</p> <p><code>include/db.php</code>:</p> <pre><code>&lt;? include_once 'include/config.php'; try { $attribs = array( PDO::ATTR_PERSISTENT =&gt; $config['db']['persistent'], PDO::ATTR_ERRMODE =&gt; $config['db']['errormode'] ); $db = new PDO( $config['db']['uri'], $config['db']['user'], $config['db']['pass'], $attribs ); $db-&gt;query("SET NAMES 'utf8'"); $db-&gt;query("SET CHARACTER SET 'utf8'"); } catch (PDOException $e) { print "Error!: " . $e-&gt;getMessage() . "&lt;br/&gt;"; die(); } function dbGetEngine() { global $config; return substr($config['db']['uri'], 0, strpos($config['db']['uri'], ':')); } ?&gt; </code></pre> <p><code>include/config.php</code>:</p> <pre><code>&lt;? //$config['db']['uri'] = 'sqlite:' . realpath('.') . '/site.db'; // PDO's database access URI $config['db']['uri'] = 'mysql:host=localhost;dbname=sitedb'; // server should be : 195.78.32.7 //$config['db']['uri'] = 'pgsql:host=localhost;dbname=sitedb'; $config['db']['user'] = 'user_goes_here'; // database username $config['db']['pass'] = 'pass_goes_here'; // database password $config['db']['persistent'] = false; // should the connection be persistent $config['db']['errormode'] = PDO::ERRMODE_EXCEPTION; // PDO's error mode ?&gt; </code></pre> <p>Included are sample connection strings for SQLite, MySQL and PostgreSQL.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload