PHP code example of m35 / thecsv

1. Go to this page and download the library: Download m35/thecsv library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

m35 / thecsv example snippets



use m35\thecsv\theCsv;
theCsv::export('tableName'); // return true if success

theCsv::export('user');


use m35\thecsv\theCsv;
theCsv::export('tableName'); // return true if success

theCsv::export('user');

theCsv::export([
    'table' => 'user',
    'fields' => ['username', 'password'],
]);

theCsv::export([
    'table' => 'user',
    'fields' => ['username', 'password'],
    'header' => ['Username', 'Password'],
]);

theCsv::export([
    'table' => 'user',
    'fields' => ['username', 'password'],
    'header' => 'no',
]);

theCsv::export([
    'query' => (new \yii\db\Query)->from('user'),
]);

$fp = fopen('./data.csv', 'w');
theCsv::export([
    'data' => [
        ['a', 'b', 'c'],
        ['A', 'B', 'C'],
    ],
    'fp' => $fp,    // fp resource you want to put the data in
]);

theCsv::export([
    'table' => 'user',
    'fields' => ['username', 'password'],
]);

theCsv::export([
    'table' => 'user',
    'fields' => ['username', 'password'],
    'header' => ['账户', '密码'],
]);

theCsv::export([
    'table' => 'user',
    'fields' => ['username', 'password'],
    'header' => 'no',
]);

theCsv::export([
    'query' => (new \yii\db\Query)->from('user'),
]);

$fp = fopen('./data.csv', 'w');
theCsv::export([
    'data' => [
        ['a', 'b', 'c'],
        ['A', 'B', 'C'],
    ],
    'fp' => $fp,    // 如果指定fp资源,则默认行为从下载变为直接写入该资源
]);