Reputation: 23
What is the deference between array('hi'=>$hello)
and array(':hi'=>$hello)
I am using the second form to insert
my data using prepare
statement by extending PDO
which is working fine. However when I change array declaration to first form array('hi'=>$hello)
no data is being inserted, I was wondering how they both work.
Upvotes: 2
Views: 51
Reputation: 326
':hi'
is a named variable and also an index/key in your array this can pass values to your database (Used in PDO).
'hi'
is just an index/key in your array
Upvotes: 1
Reputation: 334
Your first example:
array('hi' => $hello);
creates a key called 'hi
', and your second example creates a key :hi
. To use PDO parameters you need to prepend the parameters with a colon. The colon is used to designate and identify the parameters.
See PDO prepared statement - what are colons in parameter names used for?
Upvotes: 0