PHP Web Host - Quality Web Hosting For All PHP Applications Clan Themes! We make clans look good!!
  Login or Register
 • Home • Downloads • Your Account • Forums • 

View next topic
View previous topic


Google
 
Web RavenPHPScripts (This Site)
Post new topic   Reply to topic
Author Message
Misha
Worker
Worker


Joined: Jul 30, 2006
Posts: 203
Location: McLean, VA

PostPosted: Fri Oct 06, 2006 8:08 pm Reply with quote Back to top

montego wrote:
Misha, it is not an "implementation question" really, but a string definition question. Everywhere that you are building a string, it is much faster to concatenate rather than parse.
Yep, I got this already, thanks. My last silly question was about sql injection danger and where I should try to prevent it, and where it does not make any sense...

On your benchmarks:
I tried hard to compare code for second and third cases, and did not find any difference. Difference in times is dramatic, though. What I am missing?

Thanks.
View user's profile Send private message Visit poster's website
montego
Site Admin


Joined: Aug 29, 2004
Posts: 9133
Location: Arizona

PostPosted: Fri Oct 06, 2006 10:10 pm Reply with quote Back to top

My bad. Sorry about that Misha. Let me dissect the actual SQL string here rather than with PHP code:


SELECT * from nuke_something WHERE field1 = 'somevalue';

This is what the actual SQL needs to end up looking like in the string that is passed to mySQL. So, yes, in order to help prevent SQL injection (notice that I said "help", not "cure"), you should place single quotes around the value. Now, if you are absolutely certain that a variable is an integer (and I mean absolutely certain because YOU made certain), you do not have to use the quotes.

So, I was writing the string definition in both the most efficient manner as well as ensuring that the single quotes were going to be around the value.

Hope that helps.

djmaze, I know, I cannot believe how many of these I cleaned up already in the upcoming RN 2.10 release (still have much more to go). How about this one:

$variable = "" . _STRINGCONSTANT . "";

Oh my....
View user's profile Send private message Visit poster's website
Gremmie
Former Moderator in Good Standing


Joined: Apr 06, 2006
Posts: 2415
Location: Iowa, USA

PostPosted: Fri Oct 06, 2006 10:10 pm Reply with quote Back to top

montego wrote:

BTW, someone mentioned HEREDOC syntax previously. It is going to be much slower as well due to the parsing that PHP must do for variable substitution. However, everything is life is about trade-offs... in some cases, you may not care about a few miliseconds or even a second (such as an admin screen), while in other cases you might prefer easier coding and readbility.


Agreed.
View user's profile Send private message
montego
Site Admin


Joined: Aug 29, 2004
Posts: 9133
Location: Arizona

PostPosted: Fri Oct 06, 2006 10:12 pm Reply with quote Back to top

Misha, by the way, the semi-colon on the end of my SELECT is a carry-over from my Oracle. I do not believe that is necessary with mySQL. I have not even looked in the db directory files to see if the Oracle sql layer is automatically suffixing the SQL string coming in, but who really cares about Oracle with nuke anyways! Wink

Regardless, don't worry too much with what I just said. Laughing
View user's profile Send private message Visit poster's website
Misha
Worker
Worker


Joined: Jul 30, 2006
Posts: 203
Location: McLean, VA

PostPosted: Fri Oct 06, 2006 10:35 pm Reply with quote Back to top

Thanks, Montego! You are educating me little by little Smile
View user's profile Send private message Visit poster's website
Display posts from previous:       
Post new topic   Reply to topic

View next topic
View previous topic
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Forums ©
 

All logos and trademarks in this site are property of their respective owner.
The comments are property of their posters, all the rest © 2002-2011 by Raven

You can syndicate our news using the file xml

CSE HTML Validator Helped Clean up This Page! [Valid RSS] valid RSS 2.0 Valid robots.txt Stop Spam Harvesters, Join Project Honey Pot

Website engines core code is © copyright by PHP-Nuke but has been heavily patched and modified by myself and others.
PHP-Nuke is a free software released under the GNU/GPL.


:: fisubice phpbb2 style by Daz :: PHP-Nuke theme by www.nukemods.com ::
:: fisubice Theme Modified by the RavenNuke™ Team ::

:: W3C CSS Compliance Validation :: W3C HTML 4.01 Transitional Compliance Validation ::

zerosum