Home  >  Article  >  Backend Development  >  PHP exports data structure and generates .sql file_PHP tutorial

PHP exports data structure and generates .sql file_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:04:131031browse

php tutorial export data structure and then generate .sql file

$database='';//Database tutorial name
$options=array(
'hostname' => '',//ip address
'charset' => 'utf8',//encoding
'filename' => $database.'.sql',//File name
'username' => '',
'password' => ''
);
mysql tutorial_connect($options['hostname'],$options['username'],$options['password'])or die("Cannot connect to the database!");
mysql_select_db($database) or die("Wrong database name!");
mysql_query("SET NAMES '{$options['charset']}'");
$data = get_insert_sql($table);


function dump_table($table, $fp = null)
{
$need_close = false;
If (is_null($fp)) {
           $fp = fopen($table . '.sql', 'w');
          $need_close = true;
}
$a=mysql_query("show create table `{$table}`");
$row=mysql_fetch_assoc($a);fwrite($fp,$row['Create Table'].';');//Export table structure
$rs = mysql_query("SELECT * FROM `{$table}`");
While ($row = mysql_fetch_row($rs)) {
            fwrite($fp, get_insert_sql($table, $row));
}
Mysql_free_result($rs);
If ($need_close) {
           fclose($fp);
}
}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/630881.htmlTechArticlephp tutorial exports the data structure and then generates the .sql file $database='';//Database tutorial name $options= array( 'hostname' = '',//ip address 'charset' = 'utf8',//encoding 'filename' = $database.'.s...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn