Difference between bindParam and bindValue in PHP


Both bindParam and bindValue are the inbuilt functions of PHP which are used for accessing database records by mapping variable to the value in PHP data objects statement also known as PDOStatement which is nothing else but is an abstraction layer for database queries.

Following are the important differences between ASP and ASP.NET.

Sr. No.KeybindParam functionbindValue function
1DefinitionbindParam is a PHP inbuilt function used to bind a parameter to the specified variable name in a sql statement for access the database record.bindValue, on the other hand, is again a PHP inbuilt function used to bind the value of parameter to the specified variable name in sql statement.
2ExecutionbindParam function is executed only at the execution of statement i.e $stmt -> bindParam(':variableName', $parameter); is called.On other hand bindValue is compiled and assign its value at the time of its declaration i.e $stmt->execute();
3Accessed ValueAs mentioned in above point bindParam is executed at the execution of statement, so the latest value mapped with parameter is being used by the statement.While on other hand, in case of bindValue the value gets assigned to the parameter at the time of declaration of the function used by the statement.
4TypeAs mentioned in above point bindParam function is of runtime execution type.On other hand bindValue function is of compiled execution type.
5Modified ValueIn case of bindParam modification in parameter value is possible and would get executed by the statement.On other hand in case of bindValue modification in parameter value is not possible and only the initial value get executed by the statement.

Updated on: 09-Jun-2020

3K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements