php tutorial export mysql tutorial data table data generation .sql file
$database='';//Database tutorial name
$options=array(
'hostname' => '',//ip address
'charset' => 'utf8',//encoding
'filename' => $database.'.sql',//File name
'username' => '',
'password' => ''
);
mysql_connect($options['hostname'],$options['username'],$options['password'])or die("Cannot connect to database!");
mysql_select_db($database) or die("Wrong database name!");
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;
}