Re: SQL Readability.. (was Re: most powerful php editor)
| From: | Stut | Date: | Fri, 26 Jan 2007 16:30:23 +0000 |
| Subject: | Re: SQL Readability.. (was Re: most powerful php editor) | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-247835@lists.php.net to get a copy of this message | ||
tg-php@gryffyndevelopment.com wrote:
My contribution to the insanity.. INSERT statements made easy: $genericQY = "INSERT INTO MOD_LMGR_Leads ("; $genericQYvalues = " VALUES (";You call that readable?? $vals = array(); $vals['FirstName'] = 'John'; $vals['LastName'] = 'Smith'; $query = mysql_query(BuildInsert('MOD_LMGR_Leads', $vals)); function BuildInsert($table, $values) {$genericQY .= " FirstName,"; $genericQYvalues .= " 'John',"; $genericQY .= " LastName"; $genericQYvalues .= " 'Smith'"; $genericQY .= " )"; $genericQYvalues .= " );";$genericQY .= $genericQYvalues; $genericRS = mysql_query($genericQY);
foreach (array_keys($values) as $key)
$values[$key] = mysql_real_escape_string($values[$key]);
$sql = 'insert into'.$table.'(`'; $sql.= implode(',', array_keys($values)); $sql.= '`) values ("'; $sql.= implode('","', array_values($values)); $sql.= '")';
return $sql;} Note that this is a *very* cut down and untested version of BuildInsert. -Stut