AJAX request runs a RAW parameterized Postgres SQL Query after receiving request
Suppose we have a situation like that
Here's my situation
in my php view file, I make AJAX request to the server
The AJAX request is received and runs a RAW parameterized Postgres SQL query (e.g.
DB::select('select * from my_table where id=?', array(1))
Then to solve this problem we will use such logging sql query.
if (Config::get('database.log', false))
{
Event::listen('illuminate.query', function($query, $bindings, $time, $name)
{
$data = compact('bindings', 'time', 'name');
// Format binding data for sql insertion
foreach ($bindings as $i => $binding)
{
if ($binding instanceof \DateTime)
{
$bindings[$i] = $binding->format('\'Y-m-d H:i:s\'');
}
else if (is_string($binding))
{
$bindings[$i] = "'$binding'";
}
}
// Insert bindings into query
$query = str_replace(array('%', '?'), array('%%', '%s'), $query);
$query = vsprintf($query, $bindings);
Log::info($query, $data);
});
}
By this way we can deal with sql logging query.
0 Comment(s)