Re: What is diff between SQL .... VALUES ($a.$b) and SQL .... VALUES (a,b)?
| From: | Alexander Skwar | Date: | Mon, 03 Sep 2001 20:20:22 +0000 |
| Subject: | Re: What is diff between SQL .... VALUES ($a.$b) and SQL .... VALUES (a,b)? | ||
| References: | 1 2 3 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-1425@lists.php.net to get a copy of this message | ||
So sprach »Jan Holland« am 2001-09-03 um 20:43:03 +0200 :
> $sql = "INSERT INTO messages (timestamp, n10cybername ,
> n12msgpub)";
> $sql .= "VALUES (unix_timestamp() , $n10cybername ,
> $n12msgpub )";
> gives:
Sorry about my last mail. In retrospective, it sounded *WAY* too harsh.
I should have given you a working example, sorry about that....
Okay, here you are:
$sql = 'INSERT INTO messages (timestamp, n10cybername, n12msgpub)';
$sql .= ' VALUES (';
$sql .= 'unix_timstamp()';
$sql .= ', "' . $n10cybername . '"';
$sql .= ', "' . $n12msgpub . '"';
$sql .= ')';
This will insert one row with three values:
- the current time as a large integer
- the value of $n10
- the value of $n12
It is necessary to quote $n10 and $n12 with " or ' so that MySQL notices
that everything between the quotes is just one value. Further, it's
neccessary, because MySQL dictates to use quotes when inserting strings.
And last, you might want to escape any ' or " which are in $n10 or $n12
with addslashes().
However, the value for the column timestamp mustn't be quoted, because
you're using a MySQL function here - unix_timstamp().
One last note - I'd *NOT* use unix_timestamp() but rather a MySQL time
column like datetime or timestamp. This allows you to easily do date
calculations inside of MySQL. And with the help of functions like
MySQL's date_format() you can easily format the date to your liking.
HTH this time.
Alexander Skwar
--
How to quote: http://learn.to/quote (german) http://quote.6x.to (english)
Homepage: http://www.digitalprojects.com | http://www.iso-top.de
iso-top.de - Die günstige Art an Linux Distributionen zu kommen
Uptime: 13 hours 12 minutes