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
(
[0] => 42000
[1] => 1064
[2] => 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.
Http://www.php.net/manual/en/pod.prepare.php
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
I already hoped that I would solved this but not quite yet. So I finally managed to got script working without any issues but now when I’m trying to implement it to Wordpress theme there is one little problem; It doesn’t work when Javascript is enabled! It catches all data and tries to sent it but it can’t insert it anywhere because it somehow loses database connection in middle of updating.
But when JS is disabled it works like a dream. Any ideas?
And sources of course:
Does anybody have any clue about this or will I settle for SQLite because at least it works either JS is enabled or not.
