[] really very urgent []cvs import MySQL garbled, please, little brother I have no points can only give these, please understand

Source: Internet
Author: User
[] really very urgent online and so on []cvs import MySQL garbled, please master guidance, I have no points can only give these, please understand
This post was last edited by Etracer on 2013-02-19 10:04:06

My CVS file format is UTF8, and the database format is UTF8_GENERAL_CI
Here is my Code, please refer to the

/**
* @author: パンこう
* @Modify:
*/


//==========================================
Common settings
//==========================================
Smarty.classの Call accolades out expands
Require_once ('.. /libs/mysmarty.class.php ');

New しく as したmysmartyインスタンスの generation
$smarty = new Mysmarty ();

if (!include_once ("postdbonload.php"));

データベース Connect Yobitsugi
$pdo = new PDO ("mysql:host= $MYSQL _host; Dbname= $MYSQL _database "," $MYSQL _user "," $MYSQL _password ");
$pdo->setattribute (Pdo::attr_errmode, pdo::errmode_exception);
$pdo->query (' SET NAMES utf8 ');

$pdo->setattribute (Pdo::mysql_attr_use_buffered_query, true);

$pdo->query (' Set CHARACTER set UTF8 ');
$pdo->query (' SET Character_set_results=utf8 ');

$action = $_get[' action '];
if ($action = = ' Import ') {//
$filename = $_files[' file ' [' Tmp_name '];
if (empty ($filename)) {
Echo ' Csvファイルを select んでください ';
Exit
}
$handle = fopen ($filename, ' R ');

$result = Input_csv ($handle); //
$len _result = count ($result);
if ($len _result==0) {
Echo ' Noデータ ';
Exit
}


for ($i = 1; $i < $len _result; $i + +) {//

$m _personalid = $result [$i][0];//personal コード
$m _membername = $result [$i][1];//Passenger
$m _katakana = $result [$i][2];//フリガナ


$gname = Trim ($result [$i][3]);//Branch
$group 2id = "SELECT * from hy_groups where g_groupname= ' $gname '";
$rs = $pdo->query ($group 2id);
$rs->setfetchmode (Pdo::fetch_both);
$result _arr = $rs->fetch ();
$m _groupid= $result _arr[' g_id ';

$m _driver_tel = $result [$i][4];//アプリ Tel

$m _driver_tel = $result [$i][5];//carrying bands
$m _driver_tel = $result [$i][6];//telephone (self-dwelling)
$m _driver_tel = $result [$i][7];//
$m _pro = $result [$i][20];//

//-----------------------

$c _clientname = $result [$i][8];//] (the club name フリガナ)
$c _clienttel = $result [$i][9];//the first phone call
$c _clientplace = $result [$i][10];//the first place of residence
$c _traveler = $result [$i][11];//ご passenger car name
$c _traveleradds = $result [$i][12];//ご passenger 様 self-residence
$c _travelermob = $result [$i][13];//ご passenger 様 telephone (carrying bands)
$c _travelertel = $result [$i][14];//ご passenger 様 telephone (self-dwelling)
$c _secretary = $result [$i][15];//to serve as a secret name
$c _secretarytel = $result [$i][16];//to serve as a secret telephone (join/carry bands)
$c _carinfo = $result [$i][17];//car tael
$c _goodpart = $result [$i][18];//the car room first
$c _emptycol = $result [$i][19];//empty linked fields
//------------------------


$data _values = "(' $m _personalid ', ' $m _membername ', ' $m _katakana ', ' $m _groupid ', ' $m _driverkmtel ', ' $m _driver_tel ', ' $m _driverhometel ', ' $m _salesstaff ', ' $m _pro ');

$querysql = "INSERT INTO Hy_members (m_personalid,m_membername,m_katakana,m_groupid,m_driverkmtel,m_driver_tel,m_ Driverhometel,m_salesstaff,m_pro) values $data _values ";//

$query = $pdo->exec ($querysql);

if ($query) {

}else{

Echo ';
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    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.