3
I made this code to create Databases:
public function addDatabase($name, $collation) {
try {
$sql = "CREATE DATABASE `:name` COLLATE `:collation`;";
// Prepare the query to execute
$query = $this->db->prepare($sql);
$parameters = array(':name' => $name, ':collation' => $collation);
// Execute the query
$query->execute($parameters);
} catch (PDOException $e) {
die("DB ERROR: ". $e->getMessage());
}
}
He wasn’t displaying any errors and no results... I redid the code without bind
public function addDatabase($name, $collation) {
try {
$sql = "CREATE DATABASE `$name` COLLATE `$collation`;";
// Prepare the query to execute
$query = $this->db->prepare($sql);
// Execute the query
$query->execute();
} catch (PDOException $e) {
die("DB ERROR: ". $e->getMessage());
}
}
And without bind worked. But I can’t leave without bind to avoid SQL Injection.
In fact PDO::quote is similar to mysqli_real_escape_string. Out of curiosity, what problems does PDO bring?
– gmsantos
One of the biggest problem is that it slows down, which can be argued against that PHP is already slow even then it doesn’t matter. It doesn’t have all that native API, not even close. It creates the illusion that you can easily switch databases, which I think is bad because you do everything by thinking about this fallacy. The API seems less intuitive perhaps for trying to generalize too much. At the time it had more disadvantages than today, it even got something. I can’t tell you how much then I can talk about something that you solved, but it was less secure, it wasn’t so flexible, things solvable, so I don’t want to say
– Maniero
And there must be something else I can’t remember right now.
– Maniero
@gmsantos The first and most glaring problem - which has now been "more or less" solved is the fact that PDO simulates Prepared statements by default - it seems that more recently they have changed this a little bit, but got this serious problem a long time. Otherwise it is an extra layer between the DB and the language, which in itself makes everything more complex and increases the surface of bugs (ie, will have all that the native driver has, and more the PDO, which only adds layers). And creates the illusion that can change DB, but in practice always have to rewrite. Almost always brings more problem than benefit.
– Bacco