Creates a backup of a MySQL database in SQL format.
function mysql_dump($database) { $query = ''; $query .= 'DROP TABLE IF EXISTS `' . $database . '.' . $table_list[$i] . '`;' . lnbr; $query .= lnbr . 'CREATE TABLE `' . $database . '.' . $table_list[$i] . '` (' . lnbr; $tmp = ''; $query .= '`' . $row['Field'] . '` ' . $row['Type']; if ($row['Null'] != 'YES') { $query .= ' NOT NULL'; } if ($row['Default'] != '') { $query .= ' DEFAULT \'' . $row['Default'] . '\''; } if ($row['Key'] == 'PRI') { $tmp = 'primary key(' . $row['Field'] . ')'; } $query .= ','. lnbr; } $query .= 'INSERT INTO `' . $database . '.' . $table_list[$i] .'` ('; while (list($key, $value) = @each($row)) { $data['keys'][] = $key; $data['values'][] = addslashes($value); } } } return $query; } }
Comments
Subscribe to comments
You need to login to post a comment.

Instead of using a "DESCRIBE ... " you can use "SHOW CREATE TABLE ... " which is easier.
and to be a pain mysqllisttables has been deprecated, as per php docs (http://nz2.php.net/mysqllisttables) , instead use "SHOW TABLES FROM $database"
It works!!! You saved my mysql project. I will recommend you web site to my friends.