Skip to content

Instantly share code, notes, and snippets.

@medeirosinacio
Last active May 8, 2025 16:00
Show Gist options
  • Save medeirosinacio/96fbef892c9aac3e4479a4126a356aa4 to your computer and use it in GitHub Desktop.
Save medeirosinacio/96fbef892c9aac3e4479a4126a356aa4 to your computer and use it in GitHub Desktop.
toRawSql
<?php
function toRawSql(string $query, array $bindings = []): string
{
foreach ($bindings as $binding) {
if (is_string($binding)) {
$binding = addslashes($binding);
$binding = "'{$binding}'";
}
$pos = strpos($query, '?');
if ($pos !== false) {
$query = substr_replace($query, (string) $binding, $pos, strlen('?'));
}
}
return $query;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment