You are reading Writing PDO prepared statements in Modx to import CSV files. You can leave a comment or trackback this post.
| M | T | W | T | F | S | S |
|---|---|---|---|---|---|---|
| « Apr | Jul » | |||||
| 1 | 2 | 3 | 4 | 5 | ||
| 6 | 7 | 8 | 9 | 10 | 11 | 12 |
| 13 | 14 | 15 | 16 | 17 | 18 | 19 |
| 20 | 21 | 22 | 23 | 24 | 25 | 26 |
| 27 | 28 | 29 | 30 | |||
Posted on June 12th, 2011 by thiswayup.
Categories: Development.
Here's a small note for myself (and anyone who just wants to knock up a quick query using XPdo and Modx Revolution). Xpdo is the ORB (Object-relational bridge) or ORM that Modx Revolution has adopted as its standard way to abstract all the data access. It also provides a thin wrapper around the standard php PDO class.
I myself like writing SQL, especially when you have to write slightly more complicated sql which an ORM just becomes a hindrance in certain situations. Recently I've had to deal with uploads of CSV files directly into Modx, here is my code for the csv file read and using the handy PDO prepared statements bit.
Some points to note when using PDO :
Here is some sample code for :
$file ="var/someplace/file.txt";
$handle = fopen($file, "r");
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$stmt = $modx->prepare(
"INSERT INTO modx_pews_buffer (event_group, month,event_date,event_descrption,event_start_time)
VALUES (:grp, :month,:date,:des,:time)");
$stmt->bindParam(':grp', $data[0],PDO::PARAM_STR,200 );
$stmt->bindParam(':month', $data[1],PDO::PARAM_STR,50);
$stmt->bindParam(':date', $data[2],PDO::PARAM_STR,200);
$stmt->bindParam(':des', $data[3],PDO::PARAM_STR,30);
$stmt->bindParam(':time', $data[4],PDO::PARAM_STR,11);
$stmt->execute();
}
Also read up :
Php manual page on Was listening to this whilst writing post.
0 comments.
Comments can contain some xhtml. Names and emails are required (emails aren't displayed), url's are optional.