dbTalk Databases Forums  

Explain SQL strange syntax, please

comp.databases comp.databases


Discuss Explain SQL strange syntax, please in the comp.databases forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Robert Giden
 
Posts: n/a

Default Explain SQL strange syntax, please - 04-02-2004 , 02:29 PM






In revising some of my old MySQL scripts, existing syntax works, but
I've no reason why (or where I got it from to begin with).

Ex. Using MySQL in PHP to INSERT a row, the VALUES segment lists some
values like this:

$setsqlcall = "INSERT INTO a_table (
a_name,
a_time )
VALUES (
'".$aname."',
'".$atime."')";

Most examples show simply '$aname' and '$atime'. Why the '".$var."'
syntax - extra pairings of 'double-quote & period ... period &
double-quote' inside paired single-quotes.

In searching for answers I have seen '"+$var+"' too.

Could sometime explain this for me. (Also, if you know where
explanation are to be found for this, I'd like to know that too.)

Thanks, RG

Reply With Quote
  #2  
Old   
Robert Stearns
 
Posts: n/a

Default Re: Explain SQL strange syntax, please - 04-03-2004 , 04:36 PM






Robert Giden wrote:
Quote:
In revising some of my old MySQL scripts, existing syntax works, but
I've no reason why (or where I got it from to begin with).

Ex. Using MySQL in PHP to INSERT a row, the VALUES segment lists some
values like this:

$setsqlcall = "INSERT INTO a_table (
a_name,
a_time )
VALUES (
'".$aname."',
'".$atime."')";

Most examples show simply '$aname' and '$atime'. Why the '".$var."'
syntax - extra pairings of 'double-quote & period ... period &
double-quote' inside paired single-quotes.

In searching for answers I have seen '"+$var+"' too.

Could sometime explain this for me. (Also, if you know where
explanation are to be found for this, I'd like to know that too.)

Thanks, RG
The statement is building a complete SQL statement by concatenating ('.'
is the concatenation operator in php, '+' in Visual Basic and maybe
PL/SQL from Oracle) 3 literal strings and 2 program variables.
Apparently a_name and a_time are not simple numeric type (Integer,
Number, Float etc.,) variables so the SQL syntax requires the
apostrophes around the corresponding values. A sample result of the
assignment, ignoring white space, might be:

INSERT INTO a_table (a_name,a_time)
VALUES('Smith','09:18:27')

If you carefully (and this can be hard in a long statement!!!) match up
the quotes (") you will see that they contain the apostrophes so that
php never sees them as php language elements, just part of the various
string literals.



Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.