Created
November 15, 2016 07:51
-
-
Save Gesparo/35b2d6af10a4a9c047559ebf33ec4f75 to your computer and use it in GitHub Desktop.
Prepare array [key => value] into sql query `key` = 'value'
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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