命令不同步;您现在无法运行此命令
我正在尝试执行我的PHP代码,该代码通过mysqli调用两个MySQL查询,并得到错误“命令不同步;您现在无法运行此命令”。
这是我正在使用的代码
<?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;
}
}
}
我已经尝试过阅读这个,但我不确定该怎么办。我已经阅读了有关商店结果和免费结果的信息,但是使用它们时这些结果没有任何区别。我不确定究竟是在哪一点上导致此错误的,并且想知道为什么会导致此错误以及如何解决它。
通过我的调试语句,countQuery的第一个if循环甚至没有被输入,因为我的sql语法在附近出现错误。但是,如果我只是选择而不是尝试基于LIKE子句进行限制,我仍然会得到命令不同步错误。'% ? %'
*