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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T22:18:39+00:00 2026-06-03T22:18:39+00:00

After creating table using exec() in PDO,it shows like this Array ( [0] =>

  • 0

After creating table using exec() in PDO,it shows like this

Array ( [0] => 00000 [1] => [2] => )

Is this an error or did I successfully create my table?
When I looked up in the database the table is created.

this is what i executed

try{

    $tbl = new PDO("mysql:host=localhost;dbname=myDB",'root',''); 
     $tbl->exec("CREATE TABLE test(fld1 CHAR(40),fld2 CHAR(40))")
     or die(print_r($tbl->errorInfo(),true));
   }
catch(Exception $e){
     echo $e.getMessage();
 } 

@Vikas,correct me if i am wrong.and this is working

    $queryTBl="CREATE TABLE test(fld1 CHAR(40),fld2 CHAR(40))";

    $evaluateTBL=tbl->exec($queryTBL);

    if ($evaluateTBL===false)
         print "Test table could not be created";
    else
         print "Successfully Created";
  • 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-03T22:18:41+00:00Added an answer on June 3, 2026 at 10:18 pm

    According to PDO::exec manual it returns number of rows affected by the query. And there is no rows affected by a CREATE query. So exec for this query will return 0 even if it was successful. And it will be evaluated false. This explains why die is called even when there is no error.

    It is better to either rely on exception or do a === false on return code of exec to decide if it failed. From the manual:

    This function may return Boolean FALSE, but may also return a non-Boolean value which evaluates to FALSE. Please read the section on Booleans for more information. Use the === operator for testing the return value of this function.

    Example of doing the same thing with exceptions:

    try {
      $connection = new PDO("mysql:host=localhost;dbname=myDB",'root','');
      $connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    
      $connection->exec('CREATE TABLE test(fld1 CHAR(40),fld2 CHAR(40))');
    } catch (PDOException $e) {
      <handle exception>
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

After creating a metaclass using Moose::Meta::Class->create , how do I instantiate a real Moose
I have a data table. After creating this table, I use data grid view
I have created HTML TABLE from JSON data of PHP using JQuery. After creating
I am creating the below table dynamically using jQuery... After executing my code I
After creating a table (by migration), I want to insert some entries directly. How
After creating the parse tree, i have to populate symbol table now. I have
After creating a new form, I usually perform this ritual: Change the name into
After creating a div on the fly with this markup: $('.circuit').prepend(<div class='component' draggable='true'>TRANSISTOR</div>); It
After dynamically creating a client-side table based on SELECT information retrieved from MySql database,
I am creating a large table dynamically using Javascript. I have realised the time

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.