Re: Mysql statement works in phpmyadmin but not in php page

From: Date: Thu, 11 Feb 2010 23:01:36 +0000
Subject: Re: Mysql statement works in phpmyadmin but not in php page
References: 1 2 3 4  Groups: php.general 
Request: Send a blank email to php-general+get-302024@lists.php.net to get a copy of this message
Op 2/11/10 10:51 PM, James McLean schreef: > On Fri, Feb 12, 2010 at 8:27 AM, Joseph Thayne <webadmin@thaynefam.org> wrote: >> >> Actually, the syntax is just fine. I personally would prefer it the way you >> mention, but there actually is nothing wrong with the syntax. >> >>> The ,'$date1'"." is not correct syntax, change it to >>> ,'".$date."' > > My personal preference these days is to use Curly braces around > variables in strings such as this, I always find excessive string > concatenation such as is often used when building SQL queries hard to > read, and IIRC there was performance implications to it as well > (though I don't have access to concrete stats right now). > > In your case, the variable would be something like this: > > $query="INSERT INTO upload_history (v_id,hour,visits,date) VALUES > ({$v_id}, {$hour}, {$visits}, '{$date}')"; actually IIRC the engine compiles that to OpCodes that equate to: $query = 'INSERT INTO upload_history (v_id,hour,visits,date) VALUES ('.$v_id.', '.$hour.', '.$visits.', '\''.{$date}.'\')'; > > Much more readable and maintainable IMO. > > No need for the trailing semicolon in SQL that uses an API like you > are using so save another char there too. > Backticks around column names are not required and IMO again they just > make the code hard to read. Just because phpMyAdmin uses them, doesn't > mean we all need to. > > Cheers >

« previous php.general (#302024) next »