note 92693 deleted from function.implode by danbrown
| From: | danbrown@php.net | Date: | Tue, 04 Aug 2009 17:08:15 +0000 |
| Subject: | note 92693 deleted from function.implode by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-159094@lists.php.net to get a copy of this message | ||
Note Submitter: adam82s at gmail dot com
----
Found it very useful when inserting sql/mysql rows,
$values =
array('firstname'=>'firstname_value','lastname'=>'lastname_value');
sprintf('INSERT INTO %s (%s) VALUES ("%s")', 'table_name',
implode(', ', array_map('mysql_escape_string', array_keys($values))),
implode('", "',array_map('mysql_escape_string', $values)));
that gives you: INSERT INTO table_name (firstname, lastname) VALUES ("firstname_value",
"lastname_value")
Very useful when dealing with tables with many columns.