Jump to content

Colons in MySQL query -- first time I've seen this


mrherman

Recommended Posts

JUDDSTER suggested this query to solve a problem.  What purpose do the colons have before "current_slot"?  Thanks.

 

SELECT SlotID FROM (
SELECT SlotID AS SlotRank, SlotID FROM UserSeats WHERE slot > :current_slot
UNION
SELECT SlotID + 8 AS SlotRank, SlotID FROM UserSeats WHERE slot <= :current_slot )
ORDER BY SlotRank

They are called "Named Parameters".... they are used in prepared statements .

Depending of which extension are you using... PDO , Mysql, Mysqli, etc. they can be accepted or not...

 

In mysqli the "?" is the equivalent and it is used like this:

SELECT SlotID FROM (
SELECT SlotID AS SlotRank, SlotID FROM UserSeats WHERE slot > ?
UNION
SELECT SlotID + 8 AS SlotRank, SlotID FROM UserSeats WHERE slot <= ? )
ORDER BY SlotRank

 

Search for "Mysql Prepared Statements" to learn more.

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.