mysql insert function

From: Date: Sun, 17 Apr 2005 17:56:23 +0000
Subject: mysql insert function
Groups: php.general 
Request: Send a blank email to php-general+get-213237@lists.php.net to get a copy of this message
Hi! I regularly need to insert data into MySQL.. and instead of writing Insert query everytime i wrote this function... and it works well.. Please see and tell is it a good idea using this..or there might be problems with it? function db_query($sql) { global $dbh; $result = mysql_query($sql,$dbh) or die(mysql_error()); return $result; } function insertArray($table, $array) { //var_dump($array); $sql1="INSERT INTO ".$table."("; $sql2=") VALUES("; while (list($key,$value) = each($array)) { //echo ("$key, $value <BR>"); $sql1=$sql1."".$key.","; $sql2=$sql2."\"".$value."\","; } $sql1=rtrim($sql1,","); $sql2=rtrim($sql2,","); $sql=$sql1.$sql2.")"; //echo $sql; db_query($sql); } And when i need to insert any data I create it as an array like below and call function: $fields=array( "Title" => $Title, "OwnerMemberId" => $memberid, "Address" => $Address, "City" => $City, "State" => $State, "Pin" => $Pin ); insertArray("Property", $fields); where Property is the table name - Free Website Promotion - A Complete Guide http://hostwindow.info/web-hosting/9/free-website-promotion/1/

« previous php.general (#213237) next »