php教程 導出 mysql教程 數據表數據生成.sql文件
$database='';//數據庫教程名
$options=array(
'hostname' => '',//ip地址
'charset' => 'utf8',//編碼
'filename' => $database.'.sql',//文件名
'username' => '',
'password' => ''
);
mysql_connect($options['hostname'],$options['username'],$options['password'])or die("不能連接數據庫!");
mysql_select_db($database) or die("數據庫名稱錯誤!");
mysql_query("SET NAMES '{$options['charset']}'");
$data = get_insert_sql($table);
function get_insert_sql($table, $row)
{
$sql = "INSERT INTO `{$table}` VALUES (";
$values = array();
foreach ($row as $value) {
$values[] = "'" . mysql_real_escape_string($value) . "'";
}
$sql .= implode(', ', $values) . ");";
return $sql;
}