The% w_that is your PDO class has the prepare , which is responsible for preparing an execution command (SQL ) and that it returns a PDOStatement a> and it has execute method, that is, $db
does not have this $db
method, but has a method that returns a PDOStatement that has the execute.
In execute
you can directly use the PDO :: query , which also returns a PDOStatement already run being the one with data return and PDO::exec , which executes Insert, Update, and Delete commands that return the number of affected rows.
//select
$db->query("SELECT * FROM BD");
//insert, update e delete
$rowsafetados = $db->exec("INSERT INTO BD ...");
Why does this all happen?
There is separation of responsibility between the classes ( POO ) and each class has its own responsibility, $db
connection and fast methods, and PDOStatement that uses $db
as a connection to its methods.