Jump to content

about using variables in a query


Go to solution Solved by mac_gyver,

Recommended Posts

so this is not an issue or anything but i was just wondering a bit about the use of variables in a query. 

with php i thought i had to use the bind parameter to be able to bind a variable value in the query. somehow i saw this in some code example :

 $query = "SELECT * FROM student LIMIT $start_from, $per_page_record";

and is not using any binding parameter, so my question is , what is the difference of use between using bind_param and directly using variables in the query , personaly i never was able to put a variable just like that in a query not that i tried a lot but once i found the bind_param function i only used this method.

Edited by alexandre
Link to comment
https://forums.phpfreaks.com/topic/315523-about-using-variables-in-a-query/
Share on other sites

  • Solution

the main point of using a prepared query, e.g. with place-holders in the sql statement where the data values are to be acted upon, then supply the actual data values when the query is executed, is to prevent any sql special characters in a data value from being able to break the sql query syntax, which is how sql injection is accomplished, by separating the parsing of the sql query syntax from the evaluation of the data values. a secondary point is they provide a performance gain (~5%) in the rare cases when you execute the same query within one instance of your script with different data values, since the sql query statement is only sent to the database server once, where it is parsed and its execution is planned only once.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.