Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9070275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T17:38:42+00:00 2026-06-16T17:38:42+00:00

This query is giving me syntax errors when I atempt to execute it in

  • 0

This query is giving me syntax errors when I atempt to execute it in PHP mysqli, but not when executed in the MySQL CLI. Can someone tell me what is happening here.

Here’s the query:

DROP TABLE IF EXISTS `wp_commentmeta`;
    CREATE TABLE `wp_commentmeta` (
      `meta_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
      `comment_id` bigint(20) unsigned NOT NULL DEFAULT '0',
      `meta_key` varchar(255) DEFAULT NULL,
      `meta_value` longtext,
      PRIMARY KEY (`meta_id`),
      KEY `comment_id` (`comment_id`),
      KEY `meta_key` (`meta_key`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1;

Here’s the test code:

<?php

$sql="
    DROP TABLE IF EXISTS `wp_commentmeta`;
    CREATE TABLE `wp_commentmeta` (
      `meta_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
      `comment_id` bigint(20) unsigned NOT NULL DEFAULT '0',
      `meta_key` varchar(255) DEFAULT NULL,
      `meta_value` longtext,
      PRIMARY KEY (`meta_id`),
      KEY `comment_id` (`comment_id`),
      KEY `meta_key` (`meta_key`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
";

$conn=mysqli_connect('localhost','root','yesthereis','test');
if(mysqli_query($conn, $sql)){
    echo "Inserted\n";
}else{
    echo "Failed\n".mysqli_error($conn)."\n";
}
?>

…and it’s execution:

jgalley@jgalley-debian:~/code/$ php test.php 
Failed
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 'CREATE TABLE `wp_commentmeta` (
      `meta_id` bigint(20) unsigned NOT NULL AUT' at line 2

As you can see, it works fine in the CLI:

jgalley@jgalley-debian:~/code/mysqlsync2$ mysql -u root -p'yesthereis' test
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 213
Server version: 5.1.63-0+squeeze1 (Debian)

Copyright (c) 2000, 2011, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> DROP TABLE IF EXISTS `wp_commentmeta`;
Query OK, 0 rows affected, 1 warning (0.05 sec)

mysql>     CREATE TABLE `wp_commentmeta` (
    ->       `meta_id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
    ->       `comment_id` bigint(20) unsigned NOT NULL DEFAULT '0',
    ->       `meta_key` varchar(255) DEFAULT NULL,
    ->       `meta_value` longtext,
    ->       PRIMARY KEY (`meta_id`),
    ->       KEY `comment_id` (`comment_id`),
    ->       KEY `meta_key` (`meta_key`)
    ->     ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
Query OK, 0 rows affected (0.01 sec)

mysql> quit
Bye
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T17:38:43+00:00Added an answer on June 16, 2026 at 5:38 pm

    You cannot run two queries in a single mysqli_query call. Break your query string in two and execute them separately. (Or, as TheVedge correctly points out in the comments, use mysqli_multi_query as a drop-in replacement for mysqli_query in your script.)

    This helps mitigate SQL injections.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

im doing this query on mysql, but its giving me duplicate results sets: this
This query gives me syntax error in when-between line. how can i solve them?
Can anybody tell why is this query not working? DECLARE @unwantedRows TABLE ( ProductId
i have this simple SQL join query, which is giving me a syntax error
Below is my query. Access does not like it, giving me the error Syntax
I have been over and over this but I can not find why it
why is this query giving weird results.. SELECT max(greatest(home_team_total,away_team_total)) AS max_team_score, id FROM `match`
This Query is giving me an error of #1054 - Unknown column 'totalamount' in
I have this query, which is giving me some problems... I am trying to
This simple query session = com.jthink.songlayer.hibernate.HibernateUtil.getSession(); Query q = session.createQuery(recNo from SongChanges); giving this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.