0
$sql = $pdo->prepare("INSERT INTO test(name,city)VALUES(:vary,'china')");
$sql->bindParam('vary',$vary, PDO::PARAM_STR);
$vary=1234;
$sql->execute();

This should give error because i am not using string, for :vary parameter . but this is working fine and insert a row in table test. can someone explain why there is no error, i find same question on stackoverflow PHP PDO::bindParam() data types.. how does it work? But i am still confused, can someone PLEASE explain better..

Community
  • 1
  • 1
beginner
  • 2,366
  • 4
  • 29
  • 53

1 Answers1

1

This doesn't give you any errors because of PHP's type juggling. In other words: PHP silently casts the integer 1234 into the string 1234, when you try to use it as a string.

Read more about the type juggling in the PHP manual.

ChristianF
  • 2,068
  • 9
  • 14