Skip to content

Instantly share code, notes, and snippets.

@Gesparo
Created November 15, 2016 07:51
Show Gist options
  • Save Gesparo/35b2d6af10a4a9c047559ebf33ec4f75 to your computer and use it in GitHub Desktop.
Save Gesparo/35b2d6af10a4a9c047559ebf33ec4f75 to your computer and use it in GitHub Desktop.
Prepare array [key => value] into sql query `key` = 'value'
/**
* Convert $fields into column value SQL query
*
* @param $fields [columnName => value]
* @return string
*/
function prepareQuery($fields)
{
$result = '';
foreach ($fields as $key=>$value)
{
$result .= "`$key` = '$value', ";
}
return empty($result) ? '' : substr($result, 0, -2);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment