Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the question mark's significance in MySQL at "WHERE column = ?"?

Tags:

syntax

mysql

I am dissecting some code and came across this,

$sql = 'SELECT page.*, author.name AS author, updator.name AS updator '      . 'FROM '.TABLE_PREFIX.'page AS page '      . 'LEFT JOIN '.TABLE_PREFIX.'user AS author ON author.id = page.created_by_id '      . 'LEFT JOIN '.TABLE_PREFIX.'user AS updator ON updator.id = page.updated_by_id '      . 'WHERE slug = ? AND parent_id = ? AND (status_id='.Page::STATUS_REVIEWED.' OR status_id='.Page::STATUS_PUBLISHED.' OR status_id='.Page::STATUS_HIDDEN.')'; 

I am wondering what the "?" does in the WHERE statement. Is it some sort of parameter holder?

like image 389
Levi Avatar asked Mar 23 '09 19:03

Levi


People also ask

What does the question mark symbol mean in SQL?

You might be looking at Prepared Statements in JDBC or something. In that case, the question marks are placeholders for parameters to the statement.

What is the use of WHERE clause in MySQL?

The WHERE clause is used to filter records. It is used to extract only those records that fulfill a specified condition.

Which operator is used to search for a specified pattern in a column in MySQL?

The LIKE operator is used in a WHERE clause to search for a specified pattern in a column.

Why is select * used in MySQL?

The SELECT statement is used to select data from a database. The data returned is stored in a result table, called the result-set.


1 Answers

Prepared statments use the '?' in MySQL to allow for binding params to the statement. Highly regarded as more secure against SQL injections if used properly. This also allows for quicker SQL queries as the request only has to be compiled once and can be reused.

like image 127
Jayrox Avatar answered Sep 30 '22 01:09

Jayrox