PHP code example of wujiangweiphp / yieldcsv

1. Go to this page and download the library: Download wujiangweiphp/yieldcsv 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/ */

    

wujiangweiphp / yieldcsv example snippets


$yieldCsv = new YieldCsv();

$query_info = array(
       'file_name'=>'your file path',
       'fields'=> array(
               'id' => '编号',
               'nickname' => '昵称',
               'age' => '年龄',
               'desc' => '简介'
            )
       );
$data = $yieldCsv->getFileData($query_info,1);
foreach($data as $k => $v){
    // your oper to insert to mysql
}

$query_info = array(
       'connect_config' => array(
           'host' => 127.0.0.1,
           'dbname' => 'test',
           'username' => 'www',
           'password' => '123456'
       ),
       'query' => 'select id,nickname,age,desc from user ',
       'fields'=> array(
               'id' => '编号',
               'nickname' => '昵称',
               'age' => '年龄',
               'desc' => '简介'
            )
       );
$yieldCsv->exportCsv($query_info,2);

$query_info = array(
       'connect_config' => array(
           'host' => 127.0.0.1,
           'dbname' => 'test',
           'username' => 'www',
           'password' => '123456'
       ),
       'query' => 'select id,nickname,age,desc from user ',
       'fields'=> array(
               'id' => '编号',
               'nickname' => '昵称',
               'age' => '年龄',
               'desc' => '简介'
            )
       );
$data = $yieldCsv->getFileData($query_info,2);
foreach($data as $k => $v){
    // your oper code
}