php备份数据库

来源:互联网 发布:淘宝的服务中心在哪里 编辑:程序博客网 时间:2024/06/06 14:18
<?phpfunction connect(){    $link = mysqli_connect("127.0.0.1", "root", "123456");    mysqli_select_db($link, "hqpro");    mysqli_query($link,"set names utf8");    return $link;}function get_all_tables($database){    $link = connect();    $sql_table = "show tables from `$database`";    $res = mysqli_query($link, $sql_table);    while ($row = mysqli_fetch_row($res)) {         $rows[]  =  $row;    }    return $rows;}function get_all_fields($tableName){    $link = connect();    $sql = "show create table $tableName";    $res = mysqli_query($link, $sql);    $row = mysqli_fetch_row($res);    //printf("%s;\n",$row[1]);    return $row[1].";\n";}$rows = get_all_tables('hqpro');print_r($rows);$p = null;for($i=0;$i<count($rows);$i++){    $p .= get_all_fields($rows[$i][0]);}$fp = fopen('./data/sql.txt','w+');fwrite($fp, $p);

0 0
原创粉丝点击