1
如何將其插入到數據庫中?將PHP數組文件插入MySQL
我有這個文件:
[player_id] => 70658
[mobile_number] => 09********
[name] => gorbani
[password] => ******
[verification_code] => KUTY6U
[subscription] => 0
[gold] => 147350
[date_joined] => 2011-04-26 20:02:40
[free_spin] => 0
[player_status] => 1
[scriptedSpin] => PLG
[message_flag] => N
[gold_award] => 0
那在一個文本文件中僅有1項出30萬以上。 我需要自動插入ff。到一個mysql數據庫,其中只有
mobile_number
name
password
gold
將被採取和插入。
謝謝。
問候, Mehihi
那是怎樣的文件被格式化:
[player_id] => 70658
[mobile_number] => 09********
[name] => gorbani
[password] => ******
[verification_code] => KUTY6U
[subscription] => 0
[gold] => 147350
[date_joined] => 2011-04-26 20:02:40
[free_spin] => 0
[player_status] => 1
[scriptedSpin] => PLG
[message_flag] => N
[gold_award] => 0
[player_id] => 70659
[mobile_number] => 09********
[name] => gorbani2
[password] => ******
[verification_code] => 22222
[subscription] => 0
[gold] => 147350
[date_joined] => 2011-04-26 20:02:40
[free_spin] => 0
[player_status] => 1
[scriptedSpin] => PLG
[message_flag] => N
[gold_award] => 0
等..
我都試過,但沒有好:
$sql = array();
foreach($myarray as $row) {
$sql[] = '('.$row['ID'].', "'.mysql_real_escape_string($row['NAME']).'","'.$row['PRICE'].'")';}
mysql_real_query('INSERT INTO table (ID, NAME,PRICE) VALUES '.implode(',', $sql));
[你有什麼試過?](http://whathaveyoutried.com)你的問題是什麼? [請閱讀關於應該發佈什麼問題的FAQ](http://stackoverflow.com/faq#questions) – ppeterka
這正是文件內容的樣子?記錄之間的任何形式的分隔符,或者「每行13行都是一條記錄,快樂解析」? – VolkerK
編輯我的帖子。謝謝。 – user1553142