note 67193 added to function.mysql-query

From: Date: Mon, 05 Jun 2006 15:26:48 +0000
Subject: note 67193 added to function.mysql-query
Groups: php.notes 
Request: Send a blank email to php-notes+get-113244@lists.php.net to get a copy of this message
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) ?> ---- Server IP: 194.246.101.61 Probable Submitter: 212.208.253.97 ---- X-Spam-Status: No, hits=3.1 required=5.0 tests=DATE_MISSING,FROM_NO_LOWER autolearn=no version=2.64 ---- Manual Page -- http://www.php.net/manual/en/function.mysql-query.php Edit -- http://master.php.net/note/edit/67193 Del: integrated -- http://master.php.net/note/delete/67193/integrated Del: useless -- http://master.php.net/note/delete/67193/useless Del: bad code -- http://master.php.net/note/delete/67193/bad+code Del: spam -- http://master.php.net/note/delete/67193/spam Del: non-english -- http://master.php.net/note/delete/67193/non-english Del: in docs -- http://master.php.net/note/delete/67193/in+docs Del: other reasons-- http://master.php.net/note/delete/67193 Reject -- http://master.php.net/note/reject/67193 Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#113244) next »