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

The Archive Base Latest Questions

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

I am trying to execute my PHP code, which calls two MySQL queries via

  • 0

I am trying to execute my PHP code, which calls two MySQL queries via mysqli, and get the error ‘Commands out of sync; you can’t run this command now’.

Here is the code I am using

<?php $con = mysqli_connect('localhost', 'user', 'password', 'db'); if (!$con) {     echo 'Can't connect to MySQL Server. Errorcode: %s\n'. Mysqli_connect_error();     exit; } $con->query('SET NAMES 'utf8''); $brand ='o'; $countQuery = 'SELECT ARTICLE_NO FROM AUCTIONS WHERE upper(ARTICLE_NAME) LIKE % ? %'; if ($numRecords = $con->prepare($countQuery)) {     $numRecords->bind_param('s', $brand);     $numRecords->execute();     $data = $con->query($countQuery) or die(print_r($con->error));     $rowcount = $data->num_rows;     $rows = getRowsByArticleSearch('test', 'Auctions', ' ');     $last = ceil($rowcount/$page_rows); }  else {  print_r($con->error); } foreach ($rows as $row) {     $pk = $row['ARTICLE_NO'];     echo '<tr>' . '\n';     echo '<td><a href='#' onclick='updateByPk(\'Layer2\', \'' . $pk . '\')'>'.$row['USERNAME'].'</a></td>' . '\n';     echo '<td><a href='#' onclick='updateByPk(\'Layer2\', \'' . $pk . '\')'>'.$row['shortDate'].'</a></td>' . '\n';     echo '<td><a href='#' onclick='deleterec(\'Layer2\', \'' . $pk . '\')'>DELETE RECORD</a></td>' . '\n';     echo '</tr>' . '\n'; } function getRowsByArticleSearch($searchString, $table, $max) {     $con = mysqli_connect('localhost', 'user', 'password', 'db');     $recordsQuery = 'SELECT ARTICLE_NO, USERNAME, ACCESSSTARTS, ARTICLE_NAME, date_format(str_to_date(ACCESSSTARTS, '%d/%m/%Y %k:%i:%s'), '%d %m %Y' ) AS shortDate FROM AUCTIONS WHERE upper(ARTICLE_NAME) LIKE '%?%' ORDER BY str_to_date(ACCESSSTARTS, '%d/%m/%Y %k:%i:%s')' . $max;     if ($getRecords = $con->prepare($recordsQuery)) {         $getRecords->bind_param('s', $searchString);         $getRecords->execute();         $getRecords->bind_result($ARTICLE_NO, $USERNAME, $ACCESSSTARTS, $ARTICLE_NAME, $shortDate);         while ($getRecords->fetch()) {             $result = $con->query($recordsQuery);             $rows = array();             while($row = $result->fetch_assoc()) {                 $rows[] = $row;             }             return $rows;         }     } } 

I have tried reading up on this, but I am unsure of what to do. I have read about store result and free result, however these have made no difference when using them. I am unsure at exactly which point this error is being caused, and would like to know why it is being caused, and how to fix it.

Going by my debug statements, the first if loop for countQuery is not even being entered, because of an error in my sql syntax near near '% ? %'. However if I just select * instead of trying to limit based on a LIKE clause, I still get the command out of sync error.

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

    You can’t have two simultaneous queries because mysqli uses unbuffered queries by default (for prepared statements; it’s the opposite for vanilla mysql_query). You can either fetch the first one into an array and loop through that, or tell mysqli to buffer the queries (using $stmt->store_result()).

    See here for details.

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

Sidebar

Ask A Question

Stats

  • Questions 60k
  • Answers 61k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer The best way is: var row = testElement .XPathSelectElements('sheetData/row[@r='2']') .FirstOrDefault();… May 11, 2026 at 9:35 am
  • added an answer HTMLParser has the functionality in the standard library. It is,… May 11, 2026 at 9:35 am
  • added an answer [quote]could do it manually, and horribly, by adding all such… May 11, 2026 at 9:35 am

Related Questions

I am trying to get simple jQuery to execute on my Content page with
I am trying to execute this SQL query prior to restoring a .BAK file
I am trying to execute a stored procedured from a linked database in MS
I am trying to execute this SQL command: SELECT page.page_namespace, pagelinks.pl_namespace, COUNT(*) FROM page,
Is it possbile to execute linux commands with java? I am trying to create
I am trying to set a javascript date so that it can be submitted
I am trying to grab the capital letters of a couple of words and
I am trying to set a flag to show or hide a page element,
I am trying to generate a report by querying 2 databases (Sybase) in classic
I am trying to do some string concatenation/formatting, but it's putting all the parameters

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.