Gossamer Forum
Home : Products : Gossamer Links : Discussions :

Re: [el noe] performance difference do_query prepare + execute

Quote Reply
Re: [el noe] performance difference do_query prepare + execute In reply to
Placeholders don't add speed as far as I'm aware. They just stop someone doing a SQL injection into your query (or breaking the query).

For example, if "Brand" was: 'the "future" starts now', then it would create the query:

Code:
SELECT * FROM glinks_Links WHERE Brand = "the "future" starts now";

Which would obviously break the query. Someone more malicious could use that to hijack your query and do stuff in the DB

If you are happy the query is sanitized, I would just stick with something like:

Code:
my $brand_id = shift;
my $query = qq|SELECT
Contact_Email
FROM glinks_Links
WHERE
BrandID = "$brand_id" LIMIT 1|;
return $DB->table('Links')->do_query($query)->fetchrow || undef;

Unless you are doing some serious amount of queries (hundreds or thousands per page), then I don't think you will find it makes a difference. Obviously make sure you have an index on BrandID as well though!

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!
Subject Author Views Date
Thread performance difference do_query prepare + execute el noe 3366 May 6, 2021, 12:09 AM
Thread Re: [el noe] performance difference do_query prepare + execute
el noe 3305 May 6, 2021, 3:36 AM
Thread Re: [el noe] performance difference do_query prepare + execute
Andy 3306 May 6, 2021, 8:03 AM
Thread Re: [Andy] performance difference do_query prepare + execute
el noe 3293 May 6, 2021, 8:35 AM
Thread Re: [el noe] performance difference do_query prepare + execute
Andy 3290 May 6, 2021, 8:56 AM
Post Re: [Andy] performance difference do_query prepare + execute
el noe 3247 May 11, 2021, 1:17 AM