note 92694 deleted from function.implode by hholzgra

From: Date: Thu, 02 Aug 2012 13:22:15 +0000
Subject: note 92694 deleted from function.implode by hholzgra
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-189764@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, <?php $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.

« previous php.notes (#189764) next »