2

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.

Matt Magallo
  • 328
  • 1
  • 20
  • Possible duplicate of [PHP prepared statement - what are parameter colon's used for?](http://stackoverflow.com/questions/17386469/php-prepared-statement-what-are-parameter-colons-used-for) – Kalkran Feb 18 '16 at 07:52

2 Answers2

1

':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

Matt Magallo
  • 328
  • 1
  • 20
0

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?

Community
  • 1
  • 1
Kalkran
  • 324
  • 1
  • 8