php - Is there a difference in putting your SQL query in a variable first rather than in the prepare? -


is there difference between following code, speed wise or preference?

$sql = "select * users username=?"; $user = $database->prepare($sql); $user->execute(array(request::post('username'))); 

vs

$user = $database->prepare("select * users username=?"); $user->execute(array(request::post('username'))); 

i have not tried benchmarking, visual difference less amount of code, why should 1 rather other, or should both?

$sql = "select * users username=?"; $user = $database->prepare($sql); $user->execute(array(request::post('username'))); 

vs

$user = $database->prepare("select * users username=?"); $user->execute(array(request::post('username'))); 

if using select statement once, don't put in variable, lessen memory , process used in creating variable , storing value.

$sql = "select * users username=?"; 

if using more once, can use variables avoid repetitive initializations

e.g instead of creating many select * users username=? instances can store in variable shorter , more modular code

there other things consider variable scope, etc...

there tiny difference ("the first 1 consumes more memory because stored string in variable") minimal , won't noticeable @ all.


Comments

Popular posts from this blog

Payment information shows nothing in one page checkout page magento -

tcpdump - How to check if server received packet (acknowledged) -