I’ve worked with PHP and MySQL before but now when I’m trying learn PDO I hit the wall for some odd reason.
So if I try to create new table with this piece of code:
$sth = $dbh->prepare("CREATE TABLE `?` (`id` INT AUTO_INCREMENT PRIMARY KEY, `rating` FLOAT(5,2), `ip` VARCHAR(16))"); $sth->execute(array($this->table));
It will create table called ‘new_rating’, with those single quotes in it. But if I try to echo $this->table it will give me just new_rating, without any extra quotes like it should. So why it adds single quotes to table name? I’m surely missing something here, but what?
Btw, I’m willing to give one Spotify invite to person who can help me to solve this little problem! (Of course only then if you can use Spotify in your country: https://www.spotify.com/fi/help/faq/availability/#country-availability)
Remove the backticks around the ? mark. CREATE TABLE `?` should be CREATE TABLE ?
I’ve tried that but then it gives me error:
Array (  => 42000  => 1064  => You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''new_rating' (`id` INT AUTO_INCREMENT PRIMARY KEY, `rating` FLOAT(5,2), `ip` VAR' at line 1 )
According to the comments in the php official docs, table name substitution is not allowed. Using the question mark will add quotes, so you will have to use php string substition before passing it to statement prepare.
I decided to go a bit different route because this issue but thanks anyway.
If you want that Spotify invite just give me you email address and I will sent it to you.
Sorry I couldn’t be more helpful
But when JS is disabled it works like a dream. Any ideas?
And sources of course: