====== qStr ======
~~NOTOC~~
== See Also ==
[[v5:reference:connection:addq|addQ()]]\\
== Syntax ==
string qStr(
string $unquotedText
)
==== Description ====
The function ''qStr()'' takes an input string, and allows it to be:
- Wrapped in single quotes.The value can then be used, for example in an SQL statement.
- Have quotes inside the string escaped in a way that is appropriate for the database. This is done wherever possible using PHP driver functions e.g. [[http://php.net/manual/en/mysqli.real-escape-string.php|MySQL real_escape_string]].
------------------------------
==== Usage ====
$string = "Patrick O'Reilly";
$SQL = "SELECT * FROM names WHERE name='$string'";
$result = $db->execute($SQL);
/*
* Execution fails due to mismatched ` characters
*/
$qString = $db->qStr($string);
/*
* function returns 'Patrick O\'Reilly' (The resulting string is database-specific)
*/
$SQL = "SELECT * FROM names WHERE name=$qString";
$result = $db->execute($SQL);
/*
* Execution succeeds
*/