Hi! Could we please enable some services and cookies to improve your experience and our website?
Online Sandbox for SQL and PHP: Write, Run, Test, and Share SQL Queries and PHP Code
<?php
function para_query($mysqli, $query, $args = [])
{
$query = str_replace("%s","'%s'",$query);
foreach ($args as $key => $val)
{
$args[$key] = mysqli_real_escape_string($mysqli, $val);
}
$query = vsprintf($query, $args);
$result = mysqli_query($mysqli, $query);
return $result;
}
$query = "SELECT * FROM sakila.film where title LIKE %s LIMIT %d";
$search = '';
$limit = 1;
$result = para_query($mysqli, $query, ["%$search%", $limit]);
echo json_encode($result->fetch_assoc());