Created
April 19, 2015 06:59
-
-
Save mazeltov7/c4e359871375884f2f92 to your computer and use it in GitHub Desktop.
PDOで複数データをまとめてinsertしたい
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 遅い、つらい | |
| $sql = "insert into hoge_table (name, screen_name) values (:name, :screen_name)"; | |
| $stmt = $dbh->prepare($sql); | |
| for($i=0;count($contents->statuses);$i++){ | |
| $params = array( | |
| ":name" => $contents->statuses[$i]->name, | |
| ":screen_name" => $contents->statuses[$i]->screen_name | |
| ) | |
| $stmt->execute($params); | |
| } | |
| // 無理やり複数value入れられないか、valueをまとめてinsert | |
| $sql = '"insert into hoge_table | |
| (name, screen_name) | |
| values' | |
| for($i=0;$i<count($contents->statuses);$i++) { | |
| .'('.$contents->statuses[$i]->name.','.$contents->statuses[$i]->screen_name.')"'; | |
| } | |
| .'"'; | |
| $stmt = $dbh->prepare($sql); | |
| $stmt->execute(); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
でよろしくいけた!:ok_woman: