PHP Generated SQL
May 21, 2008 · 1 minute readCategory: mysqlphp
This is post is now quite old and the the information it contains may be out of date or innacurate.
If you find any errors or have any suggestions to update the information please let us know or create a pull request on GitHub
Imagine this:
$sql_query = mysql_query("select * from table");
$insert_elsewhere_sql = "INSERT INTO other_table SET ";
while($s = mysql_fetch_assoc($sql_query)){
foreach($s as $k=>$v){
$insert_elsewhere_sql .= "$k = '$v', ";
}
$insert_elsewhere_sql = substr($insert_elsewhere_sql, 0, -2);
This will generate a valid SQL insert statement with all of your field, value pairs set up.
Time saver or what?