I have the following doubt about PDO:
If I will execute multiple queries I need to use bindParam method each time I call prepare?
Example:
$connection->prepare( "SELECT * FROM table WHERE y = :y" );
$connection->bindParam( ":y", $y );
$connection->prepare( "SELECT * FROM table2 WHERE y = :w" );
$connection->bindParam( ":w", $w );
OR Can I do better using something like:
$connection->bindParam( ":y", $y );
$connection->bindParam( ":w", $w );
$connection->prepare( "SELECT * FROM table WHERE y = :y" );
$connection->prepare( "SELECT * FROM table2 WHERE y = :w" );
OR:
$connection->prepare( "SELECT * FROM table WHERE y = :y" );
$connection->prepare( "SELECT * FROM table2 WHERE y = :w" );
$connection->bindParam( ":y", $y );
$connection->bindParam( ":w", $w );
¿Wich order and what is possible?
When you bind params you bind them to a prepared statement not to a connection, so this actually wouldn't work
$connection->bindParam( ":w", $w );
Instead, you would need to do:
$stmt = $connection->prepare( "SELECT * FROM table2 WHERE y = :w" );
$stmt->bindParam( ":w", $w );
Which automatically implies that you need to bind parameters separately for each statement.