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 8436125
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:06:13+00:00 2026-06-10T07:06:13+00:00

Using PHP PDO query to execute a mySQL query. The query is made up

  • 0

Using PHP PDO query to execute a mySQL query. The query is made up of a multitude of information inputted from foreach(); so I have echo’d out the sql query. The problem lies here but I cannot see it.

This is the output of $sql

CREATE TABLE IF NOT EXISTS `page` (
  `page_ID` INT AUTO_INCREMENT NOT NULL,
  `url` varchar(200) NOT NULL,
  `title` varchar(200),
  `subtitle` TEXT,
  `content` TEXT,
  `parent` varchar(10),
  `privacy` varchar(1),
  `status` varchar(1),
  `creation` varchar(30)
) CHARACTER SET utf8 COLLATE utf8_general_ci;

FYI the query is executed like this:

function createdbtable($table,$fields){
    global $fsdbh;
    $sql = "CREATE TABLE IF NOT EXISTS `$table` (";
    foreach($fields as $field => $type){ $sql.= "`$field` $type,"; }
    $sql = rtrim($sql,',');
    $sql .= ") CHARACTER SET utf8 COLLATE utf8_general_ci"; return $sql;
    if($fsdbh->exec($sql) !== false) { return 1; }
}

This is the error:

#1075 – Incorrect table definition; there can be only one auto column and it must be defined as a key

  • 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-10T07:06:14+00:00Added an answer on June 10, 2026 at 7:06 am

    You forgot the primary key:

    CREATE TABLE IF NOT EXISTS `page` (
    `page_ID` INT AUTO_INCREMENT NOT NULL,
    `url` varchar(200) NOT NULL,
    `title` varchar(200),
    `subtitle` TEXT,
    `content` TEXT,
    `parent` varchar(10),
    `privacy` varchar(1),
    `status` varchar(1),
    `creation` varchar(30),
    PRIMARY KEY (`page_ID`)) 
    CHARACTER SET utf8 COLLATE utf8_general_ci
    

    Error was quite explicit:

    Schema Creation Failed: Incorrect table definition; there can be only one auto column and it must be defined as a key

    You must specify the auto increment key as key.

    edit:

    And for the PHP code, I will go to something like that:

    function createdbtable($table,$fields)
    {
        global $fsdbh;
    
        $sql = "CREATE TABLE IF NOT EXISTS `$table` (";
        $pk  = '';
    
        foreach($fields as $field => $type)
        {
          $sql.= "`$field` $type,";
    
          if (preg_match('/AUTO_INCREMENT/i', $type))
          {
            $pk = $field;
          }
        }
    
        $sql = rtrim($sql,',') . ', PRIMARY KEY (`'.$pk.'`)';
    
        $sql .= ") CHARACTER SET utf8 COLLATE utf8_general_ci";
        if($fsdbh->exec($sql) !== false) { return 1; }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i am using php with pdo , when i run a mysql query, is
I have all my sites built on php and mysql stack using PDO. I
I would like to know what query is executed using PHP PDO. I have:
I am making a transfer from using mysql query lines to PDO for a
Im using MySQL with PDO PHP scripts to maintain a user database and a
I have started using PDO in php for the first time. Here is my
I'm using PDO in my PHP application. It connects to a MySQL server on
I'm using PDO to insert a record (mysql and php) $stmt->bindParam(':field1', $field1, PDO::PARAM_STR); $stmt->bindParam(':field2',
Using PHP I echo out table rows in a loop like this: <?php /*
I have a problem in a php script where I am using PDO to

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.