Solved

Why is this table not being dropped?

Posted on 2014-10-27
6
99 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 109

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 500 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
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
LVL 58

Expert Comment

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

Author Comment

by:brucegust
ID: 40406712
The backticks did it!

Thanks, Gary!
0
 
LVL 109

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
The viewer will learn how to count occurrences of each item in an array.
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.

831 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