note 67193 deleted from function.mysql-query by philip
| From: | philip@php.net | Date: | Fri, 04 Sep 2015 19:17:28 +0000 |
| Subject: | note 67193 deleted from function.mysql-query by philip | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-203639@lists.php.net to get a copy of this message | ||
Note Submitter: cedric ___at___ sadai ___dot___ net
----
This is a quick way for adding data to a table. It is the same way than PEAR::DB, so if you are
working on a server without PEAR, it enables you to keep up with your habits.
<?php
function insertIntoDB($table, $toAdd)
{
$fields = implode(array_keys($toAdd), ',');
$values = implode(array_values($toAdd), ',');
$q = 'INSERT INTO
'.$table.' ('.$fields.') VALUES
('.$values.')';
$res = mysql_query($q)OR die(mysql_error());
return true;
}
//-- Example of usage
$tToAdd = array('id'=>3, 'name'=>'Yo', 'salary' =>
5000);
insertIntoDB('myTable', $tToAdd)
?>