Solved

Why is this table not being dropped?

Posted on 2014-10-27
6
89 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 108

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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
LVL 58

Expert Comment

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

Author Comment

by:brucegust
ID: 40406712
The backticks did it!

Thanks, Gary!
0
 
LVL 108

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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.

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now