mysql - Is it different a SQL query inside of stored procedure than a SQL executed from PHP? -


let me explain.

i used large select sentence multiple joins inside php code. it's big because joins depends on values first tables (something if table1.column_a=1 alias_b=table2.column_a, if table1.column_a=2 alias_b=table3.column_b, ...) , because send condition html form can changed dynamically (sometimes have some_date>='2017/09/01', turn more complex some_date>='2017/09/01' , (name j%on not sec_name='doe') ...").

i received instruction of make stored procedure query , more time take analyze can't find way make query dynamic without putting inside of string stored procedure , receiving condition stored procedure parametter (in stored procedure have somthing set @sql = concat('select ... join ... join... ',param_condition); prepare stmt @sql;..." )

my question is... same sending sql php?

yes, preparing , executing statement stored procedure pretty same sending query php. difference whether work of concatenating pieces done in php code running on client, or mysql server.

if contents of query being constructed dependent on other table data, may better in stored procedure, don't need multiple round trips between database , php information.

but if it's dependent on parameters available in php, it's best construct query in php, if because (imho) php syntax easier understand. performance difference should minor -- string concatenation simple both php , mysql. think isn't dependent on sql data should not done in database server.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -