note 101488 added to function.mysql-query

From: Date: Mon, 20 Dec 2010 17:12:17 +0000
Subject: note 101488 added to function.mysql-query
Groups: php.notes 
Request: Send a blank email to php-notes+get-175079@lists.php.net to get a copy of this message
Use this to neatly insert data into a mysql table: <?php function mysql_insert($table, $inserts) { $values = array_map('mysql_real_escape_string', array_values($inserts)); $keys = array_keys($inserts); return mysql_query('INSERT INTO '.$table.' ('.implode(',', $keys).') VALUES (\''.implode('\',\'', $values).'\')'); } ?> For example: <?php mysql_insert('cars', array( 'make' => 'Aston Martin', 'model' => 'DB9', 'year' => '2009', )); ?> ---- Server IP: 69.147.83.197 Probable Submitter: 85.210.187.127 ---- Manual Page -- http://www.php.net/manual/en/function.mysql-query.php Edit -- https://master.php.net/note/edit/101488 Del: integrated -- https://master.php.net/note/delete/101488/integrated Del: useless -- https://master.php.net/note/delete/101488/useless Del: bad code -- https://master.php.net/note/delete/101488/bad+code Del: spam -- https://master.php.net/note/delete/101488/spam Del: non-english -- https://master.php.net/note/delete/101488/non-english Del: in docs -- https://master.php.net/note/delete/101488/in+docs Del: other reasons-- https://master.php.net/note/delete/101488 Reject -- https://master.php.net/note/reject/101488 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#175079) next »