0

I am reading about http://de.php.net/manual/en/pdostatement.execute.php but got confused with the difference between $sth->bindParam(...) and $sth->execute($parameters)

On hindsight, they look the same. Also the manual is never specific. Why or when to use PDO::PARAM_INT and PDO::PARAM_STR ?

Lastly, on my code wont return FALSE when the query is "empty".

$sql = 'SELECT `id` FROM `some WORKING sql Statement` WHERE `id` = :id';
$query  = self::$dbc->prepare( $sql );
$SHT->bindParam(':uri', $id, PDO::PARAM_INT);
$result = $SHT->execute(); //Row Count not working
if($result) {
    //TRUE
    ...code
}
else {
    //FALSE
    ...code
}
Omar
  • 11,783
  • 21
  • 84
  • 114

1 Answers1

2

bindParam() binds by reference. It means that if you first execute your prepared statement, and then change the value of the variable and then execute again then the query will be run with the updated value.

execute() with arguments: you just supply the arguments but nothing more happens.

By default all placeholders are wrapped with quotes. If you need it without quotes you can use PDO::PARAM_INT to explicitly tell PDO you want it as an integer.

The return of execute() is a statement handle. If your query executes successfully you will get a statement handle back. Use rowCount() to check if you got any rows back.

silkfire
  • 24,585
  • 15
  • 82
  • 105