Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Why is this table not being dropped?

Posted on 2014-10-27
6
Medium Priority
?
126 Views
Last Modified: 2014-10-27
Need to drop a table. My code looks like this:

$the_twitter_table = "tw_2013-11-06";
$matt = "drop table $the_twitter_table";
$matt_query=mysqli_query($cxn, $matt);
if(!$matt_query)
{
$nuts=mysqli_errno($cxn).': '.mysqli_error($cxn);
die($nuts);
}

The error I get is "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 ''tw_2013-11-06'' at line 1"

When I run drop table tw_2013-11-06 in my phpMyAdmin interface, it works great, but I'm blowing it somewhere when I try to do it via PHP. What am I missing?
0
Comment
Question by:brucegust
  • 2
  • 2
  • 2
6 Comments
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 40406695
Put single quotes around the table name.

Instead of this:
$matt = "drop table $the_twitter_table";

Try this:
$matt = "DROP TABLE '$the_twitter_table' ";

Sidebar note: The capitalization is not necessary, but experienced programmers use it to make the SQL commands stand out, and it's often a programming standard in professionally run organizations.  Do whatever you think is right :-)
0
 
LVL 58

Accepted Solution

by:
Gary earned 2000 total points
ID: 40406701
Use backticks

$matt = "drop table `$the_twitter_table`";

Open in new window

0
 

Author Comment

by:brucegust
ID: 40406704
I tried that, Ray, and it still came up short. Same error. What else could it be?
0
Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

 
LVL 58

Expert Comment

by:Gary
ID: 40406709
Ahem ^^^^^
0
 

Author Comment

by:brucegust
ID: 40406712
The backticks did it!

Thanks, Gary!
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 40406803
My apologies - I've never even considered putting a hyphen into a table or column name before.  Now that I'm testing this, I'm looking at your message:

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 ''tw_2013-11-06'' at line 1

... and wondering why it's different from the message that I get when I run your original query:

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 '-11-06' at line 1 QUERY: DROP TABLE tw_2013-11-06
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Containers like Docker and Rocket are getting more popular every day. In my conversations with customers, they consistently ask what containers are and how they can use them in their environment. If you’re as curious as most people, read on. . .
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question