Jump to content

Recommended Posts

Hi everyone,

 

Could someone please shed some light on the correct use of brackets { and } in a MySQL query.

 

For example, I understand that the following query is not entirely correct:

<?php
$sql = "SELECT id, title, date, description, publish FROM $dbtable WHERE title LIKE '$search%' || body 
LIKE '$search%' && publish='yes' ORDER by id DESC LIMIT '$offset', '$limit'";
?>

 

Rather, the following should be used but is this actually correct?:

<?php
$sql = "SELECT id, title, date, description, publish FROM $dbtable WHERE title LIKE '{$search}%' || body
LIKE '{$search}%' && publish='yes' ORDER by id DESC LIMIT '{$offset}', '{$limit}'";
?>

 

I have looked this up on the net, but there seem to be many conflicting opinions.

 

Thanks to anyone who can shed some light.

Regards,

Iceman

Link to comment
https://forums.phpfreaks.com/topic/64047-correct-use-of-brackets/
Share on other sites

personally i only use{} when i include an array ie

 

$sql = "SELECT id, title, date, description, publish FROM $dbtable WHERE title LIKE '$search%' || body 
LIKE '$search%' && publish='{DATA['publish']}' ORDER by id DESC LIMIT '$offset', '$limit'";

 

 

note the publish='{DATA['publish']}'

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.