|
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>
[Back to original message]
|