Re: SQL Readability.. (was Re: most powerful php editor)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



tg-php@xxxxxxxxxxxxxxxxxxxxxx wrote:
My contribution to the insanity..  INSERT statements made easy:

$genericQY  = "INSERT INTO MOD_LMGR_Leads (";  $genericQYvalues  = " VALUES (";
$genericQY .= " FirstName,";                   $genericQYvalues .= " 'John',";
$genericQY .= " LastName";                     $genericQYvalues .= " 'Smith'";
$genericQY .= " )";                            $genericQYvalues .= " );";
$genericQY .= $genericQYvalues;
$genericRS = mysql_query($genericQY);

You call that readable??

$vals = array();
$vals['FirstName'] = 'John';
$vals['LastName'] = 'Smith';
$query = mysql_query(BuildInsert('MOD_LMGR_Leads', $vals));

function BuildInsert($table, $values)
{
    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

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux