PHP將資料庫內容轉化為csv檔案,

來源:互聯網
上載者:User

PHP將資料庫內容轉化為csv檔案,

PHP將資料庫內容轉化為csv檔案,以逗號隔開,為防止資料庫內容中含有逗號,影響檔案內容顯示,需注意添加““(雙引號)!!!


<?phpinclude “init.php”;$file_name_=’file.csv’;$str_content_=”aid,username,password,role,status,created_time,updated_time\n”;file_put_contents($file_name_,$str_content_);$query = “select * from administrator”;$list = MysqliClient::ExecuteQuery(‘intern’, $query);foreach($list as $row){foreach($row as $col){$str_content_=$col.”,”;file_put_contents($file_name_,$str_content_,FILE_APPEND);}file_put_contents($file_name_,”\n”,FILE_APPEND);}


原文:http://www.phpthinking.com/archives/240




相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.