如何使用PHP代码或Codeigniter以.sql扩展名导出mysql数据库 [英] How to export mysql database in .sql extension using php code or in codeigniter

查看:45
本文介绍了如何使用PHP代码或Codeigniter以.sql扩展名导出mysql数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用php代码或codeigniter代码下载.sql文件!

How Can I download .sql file using php code or codeigniter code!

推荐答案

$this->dbutil->backup()

允许您备份整个数据库或单个表.备份数据可以Zip或Gzip格式压缩.

Permits you to backup your full database or individual tables. The backup data can be compressed in either Zip or Gzip format.

注意:此功能仅适用于MySQL数据库.注意:由于PHP的执行时间和内存有限,可能无法备份非常大的数据库.如果数据库很大,则可能需要通过命令行直接从SQL Server进行备份,或者,如果您没有root特权,请让服务器管理员为您进行备份.

Note: This features is only available for MySQL databases. Note: Due to the limited execution time and memory available to PHP, backing up very large databases may not be possible. If your database is very large you might need to backup directly from your SQL server via the command line, or have your server admin do it for you if you do not have root privileges.

用法示例

// Load the DB utility class
$this->load->dbutil();

// Backup your entire database and assign it to a variable


$backup =& $this->dbutil->backup(); 

// Load the file helper and write the file to your server

$this->load->helper('file');

write_file('/path/to/mybackup.sql', $backup); 

// Load the download helper and send the file to your desktop

$this->load->helper('download');

force_download('mybackup.sql', $backup);

跟踪链接

这篇关于如何使用PHP代码或Codeigniter以.sql扩展名导出mysql数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆