What does %s
mean?
$sql = "SELECT *
FROM page_table
WHERE page_name = '%s'
LIMIT 1";
The LIKE operator is used in a WHERE clause to search for a specified pattern in a column. There are two wildcards often used in conjunction with the LIKE operator: The percent sign (%) represents zero, one, or multiple characters. The underscore sign (_) represents one, single character.
This syntax works outside of classes as well. From the documentation: d - the argument is treated as an integer, and presented as a (signed) decimal number. s - the argument is treated as and presented as a string.
In SQL Server, symbol @@ is prefixed to global variables. The server maintains all the global variables.
It is a formatted string where %s
is a placeholder. I suspect that $sql is handed to sprintf to transform it into a real query. Example:
$name = 'posts';
$sql = "SELECT * FROM page_table WHERE page_name = '%s' LIMIT 1";
$formattedSql = sprintf($sql, $name);
This will generate a query looking like:
SELECT * FROM page_table WHERE page_name = 'posts' LIMIT 1
This is very useful when you don't want to fiddle around with quotes and doublequotes.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With