exceldb / dbtoexcel
关于此包最新版本(1.0.0)没有可用的许可证信息。
PHP 脚本,用于简化将数据库表转换为电子表格的过程。
1.0.0
2023-02-06 19:35 UTC
README
PHP 脚本,用于简化将数据库表转换为电子表格的过程。
# 要求
- PHP 7.0 或更高版本
- Composer 用于安装
# 安装
通过 composer
composer require exceldb/dbtoexcel
# 示例
// don't forget to import vendor/autoload.php require('vendor/autoload.php'); // Database information $extract = new Database\Excel\ExtractExcel([ 'driver' => 'mysql', 'host' => '127.0.0.1', 'username' => 'root', 'password' => '', 'database' => 'test', 'port' => '3306', 'charset' => 'utf8', 'sslmode' => 'disable' ]); $extract->table('users'); // Specify the database table. $extract->columns('*'); // Specify the columns you need to extract. $extract->execute(); // Execute the script.
# 描述
TableToExcel 类构造函数接受一个参数,即数据库信息的 (数组)。
table()
此方法用于指定需要提取的数据库表,它接受一个参数 (字符串),即表的名称。
columns()
用于指定需要从数据库表中提取的列,它接受一个参数 (字符串),即列的名称。
要提取所有列,只需添加 星号 (*) 或留空参数,如果需要提取特定列,可以按逗号分隔符写出列名。请参见下面的示例。
use ExtractDatabaseToExcel\TableToExcel; $extract = new TableToExcel([ 'driver' => 'mysql', 'host' => '127.0.0.1', 'username' => 'root', 'password' => '', 'database' => 'test', 'port' => '3306', 'charset' => 'utf8' ]); $extract->table('users'); $extract->columns('username, email, age'); // Extract specific columns $extract->execute();
execute()
这是您应该调用的最后一个方法来执行脚本,该方法将转换数据并下载电子表格文件。