In PHP, mysqli_quote_string() (PHP 8.6+) escapes a string using the connection charset and wraps it in single quotes so it can be pasted into SQL as a string literal.
On older PHP there is no widely portable mysqli_quote_string() helper in classic docs — use mysqli_prepare() (best) or mysqli_real_escape_string() plus your own quotes. Treat this page as quoting guidance: prepared statements first, real_escape_string as the classic escape API, quote_string only where PHP 8.6+ is guaranteed.
Syntax
Call mysqli_quote_string() with the values you need. Start with this line.
PHP 8.6+: returns a quoted literal such as "'O\'Reilly'".
mysqli_real_escape_string($mysqli, $s)
Portable escape API (does not add quotes).
mysqli_prepare($mysqli, "SELECT * FROM t WHERE name = ?")
Preferred: bind the value instead of quoting it.
Be honest in real projects: prefer prepare/bind for values. If you must build SQL strings on older PHP, call mysqli_set_charset() then mysqli_real_escape_string(), and add quotes yourself. quote_string is nicer when available because it both escapes and quotes, including safer behavior under NO_BACKSLASH_ESCAPES.