Login   Register  
PHP Classes
elePHPant
Icontem

addQuotes by BuildSQLColumns

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us

      Ultimate MySQL  >  All threads  >  addQuotes by BuildSQLColumns  >  (Un) Subscribe thread alerts  
Subject:addQuotes by BuildSQLColumns
Summary:BuildSQLColumns function
Messages:1
Author:William Ghilardi
Date:2013-02-17 14:22:59
 

  1. addQuotes by BuildSQLColumns   Reply   Report abuse  
Picture of William Ghilardi
William Ghilardi
2013-02-17 14:22:59
/**
* [STATIC] Builds a comma delimited list of columns for use with SQL
*
* @param array $valuesArray An array containing the column names.
* @param boolean $addQuotes (Optional) TRUE to add quotes
* @param boolean $showAlias (Optional) TRUE to show column alias
* @return string Returns the SQL column list
*/
static private function BuildSQLColumns($columns, $addQuotes , $showAlias = true) {
switch($addQuotes) {
case 1:
$quote = "`";
break;
case 2:
$quote = "'";
break;
default:
$quote = "";
break;
}
switch (gettype($columns)) {
case "array":
$sql = "";
foreach ($columns as $key => $value) {
// Build the columns
if (strlen($sql) == 0) {
$sql = $quote . $value . $quote;
} else {
$sql .= ", " . $quote . $value . $quote;
}
if ($showAlias && is_string($key) && (! empty($key))) {
$sql .= ' AS "' . $key . '"';
}
}
return $sql;
break;
case "string":
return $quote . $columns . $quote;
break;
default:
return false;
break;
}
}