Skip to content

Instantly share code, notes, and snippets.

@Anahkiasen
Created May 27, 2014 13:06
Show Gist options
  • Save Anahkiasen/6ae7f2904f1dc1febfa9 to your computer and use it in GitHub Desktop.
Save Anahkiasen/6ae7f2904f1dc1febfa9 to your computer and use it in GitHub Desktop.
/**
* Transform a Query object to its SQL value
*
* @param Query $query
*
* @return string
*/
function queryToSql($query)
{
// Unnest query objects
while (method_exists($query, 'getQuery')) {
$query = $query->getQuery();
}
// Replace bindings
$sql = str_replace('?', '%s', $query->toSql());
$sql = vsprintf($sql, $query->getBindings());
return $sql;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment