You are here: dumping a array into PDO::db using place holders. « PHP Programming Language « IT news, forums, messages
dumping a array into PDO::db using place holders.

Posted by Rowan on 01/07/08 04:15

I'm trying to enter data from an array ( eg entry1=(x=>y,a=b),
entry2=(x=>y,a=>c)) I'm trying to use place holders to dump the data.
It maybe late but I can't get this to work. below is the actual
routine used to exec. any idea on how to better format this.


<snippet> sql statement
INSERT INTO contacts ( name_first, name_last, personal_street,
personal_city, personal_state, personal_zip, personal_phone_home,
company_phone, personal_phone_cell) VALUES
( ?, ?, ?, ?, ?, ?, ?, ?, ?);
</snippet>

<snippet>
public function db_update_i($sql,$data) {
$str_check = explode(" ", $sql);
if($str_check[0] == "INSERT") {
if (is_null(db_cxn::$dbh)){
db_cxn::$dbh = self::cxn();
print 'db_cxn::db_update::> a new instance of $dbh <br/>';
}
print "$sql <br/>";
$stmnt = db_cxn::$dbh->prepare($sql);
foreach ($data as $arr) {
//krumo($arr);
$i = 1;
foreach ($arr as $key =>$value){
print "$value <br/>";
$stmnt->bindParam($i, $value);
$i++;
}
$stmnt->execute();

}
$stmnt = null;
$sql = null;
return 1;
}else{
print "Error!: Incorrectly Formatted SQL Statement";
}
}

}
</snippet>

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация