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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:31:10+00:00 2026-05-28T07:31:10+00:00

We have a method which initialises a test database as follows: $db=file_get_contents(‘test-data.sql’); /* @var

  • 0

We have a method which initialises a test database as follows:

    $db=file_get_contents('test-data.sql');

    /* @var $result mysqli_result */
    $result=self::$_mysqlConn->multi_query($db);
    if (!$result) {
        fwrite(STDERR, self::$_mysqlConn->error."\nBUILD FAILED!\n");
        exit(1);
    }

    while ($nextResRes = self::$_mysqlConn->next_result()) {
        $tempRes = self::$_mysqlConn->store_result();
        if (!self::$_mysqlConn->more_results()) break;
    }

    if (self::$_mysqlConn->errno) {
        fwrite(STDERR, "DB QUERIES FAILED. FILE: ".$file."\n");
        fwrite(STDERR, self::$_mysqlConn->error."\nBUILD FAILED!\n");
        exit(1);
    }

The build is currently failing because of one of the queries in the data.sql file. The error being returned isn’t very helpful:

DB QUERIES FAILED. FILE: data
Column count doesn't match value count at row 1
BUILD FAILED!

I’d like to somehow output the specific query which failed to STDERR at this point. How do I achieve this with MySQLi?

  • 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-05-28T07:31:10+00:00Added an answer on May 28, 2026 at 7:31 am

    You will have to split your multi-query string and run the queries individually. AFAIK there is no way to extract the query from MySQLi. You could obviously just split on ; but that is potentially going cause errors (e.g. if one of your queries uses a string containing a ;) and really you need to ensure that your test-data.sql file contains strings delimited by something that will never appear in a query.

    One approach to this which should be safe is to split on ;\n and ensure that all your queries are separated with new lines, and the a literal new line never appears in a query – essentially ensure you always use \n (which you should do anyway).

    For example (Note: I am not sure how or even if store_result() will work here – I have taken a best guess but this is untested and may need to be adapted):

    test-data.sql:

    INSERT INTO someTable
      (col1, col2, col3)
    VALUES
      ('val1', 'val2', 'val3');
    
    UPDATE someTable SET col1 = 'val' WHERE id = 4;
    
    DELETE FROM someTable WHERE id > 7;
    

    PHP:

    // Get data from file and create an array of queries
    $db = file_get_contents('test-data.sql');
    $queries = explode(";\n", $db);
    
    // Loop queries
    foreach ($queries as $query) {
    
        // Trim whitespace and skip empty queries (mostly useful for last one)
        if (($query = trim($query)) === '') continue;
    
        // Do this query
        $result = self::$_mysqlConn->query($query);
        if (!$result) {
            fwrite(STDERR, self::$_mysqlConn->error."\nQuery: $query\nBUILD FAILED!\n");
            exit(1);
        }
    
        // Store result (?)
        self::$_mysqlConn->store_result();
    
        // This may not be the best place for this and it may not even be required
        // any more - that's a decision for you really
        if (self::$_mysqlConn->errno) {
            fwrite(STDERR, "DB QUERIES FAILED. FILE: ".$file."\n");
            exit(1);
        }
    
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have created an application which inserts data into a SQL database. Basically, from
I have a method which takes params object[] such as: void Foo(params object[] items)
I have a method which should be executed in an exclusive fashion. Basically, it's
I have an method which save files to the internet, it works but just
I have a method which is given the parameter bool sortAscending. Now I want
I have a method which should be delayed from running for a specified amount
I have a method which constructs an object, calls an Execute method, and frees
I have a method which never returns a null object. I want to make
I have a method which takes String argument. In some cases I want to
i have a method which takes in a DotNetOpenAuth (formally known as DotNetOpenId) Response

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.