KISS principle:phpMyAdminを使用しますか?それはほぼ確実にインストールされています。そうでなければ、install it。
そのインポート機能は素晴らしいです。あなたのデータベースが多すぎる場合は、gzipしてください。それでもまだ大きければ、いくつかの部分に分割してみてください。私はあなたが単一の大きな取引としてそれを転送する必要があるかどうかは疑問です。あなたは?
最初のコメントの説明の後、よく、ここに行きます。これはあなたが望むことをする非常に単純なスクリプトです。セパレータを見ない限り、1つのクエリ== 1行です。
<link rel="stylesheet" href="style/contents.css"/>
<?
function timesanitize($v) {
if ($v > 0)
return round($v, 4);
else
return 0;
}
$startmt = microtime();
include_once 'include/db.php';
$f = fopen("db.sql","r");
echo dbGetEngine() . "<br>";
echo "<ul>";
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 "<li>".nl2br(htmlspecialchars($l));
$mt = microtime();
$db->query($l);
echo "<ul><li>ok - " . timesanitize(microtime() - $mt) . "</ul>";
} catch (PDOException $e) {
echo "<ul><li>".$e->getMessage() . "</ul>";
}
} while (!feof($f));
fclose($f);
echo 'total: ' . timesanitize(microtime() - $startmt);
?>
また、各クエリの所要時間の小さな統計情報も出力されます。 PDOをベースにしています。私は、PDOがPHP5.1またはPHP5.2で導入されたと信じています。私は、mysql_*()
関数で直接動作するように修正するのは簡単ではないと思っています。
もう一度:はい、私はそれが吸うことを知っています。
include/db.php
:
しかし、限り、それは私のための作品として(TM)、そしておそらくあなたが... :-)
コードを完了するには、ここではinclude/db.php
とサンプルinclude/config.php
です
<?
include_once 'include/config.php';
try {
$attribs =
array(
PDO::ATTR_PERSISTENT => $config['db']['persistent'],
PDO::ATTR_ERRMODE => $config['db']['errormode']
);
$db = new PDO(
$config['db']['uri'],
$config['db']['user'],
$config['db']['pass'],
$attribs
);
$db->query("SET NAMES 'utf8'");
$db->query("SET CHARACTER SET 'utf8'");
} catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
function dbGetEngine() {
global $config;
return substr($config['db']['uri'], 0, strpos($config['db']['uri'], ':'));
}
?>
include/config.php
:
<?
//$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
?>
を含めますdはSQLite、MySQL、PostgreSQLのサンプル接続文字列です。
私が使用した共有ホストは、コントロールパネル以外の場所からデータベースやユーザーを作成させないようにしてください。 – grapefrukt