Jump to content

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


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.

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.