gpt4 book ai didi

php - 使用 mysqli 计算行数并传递信息

转载 作者:行者123 更新时间:2023-11-29 09:23:23 24 4
gpt4 key购买 nike

我一直在尝试将 php 页面转换为 mysqli,但遇到了一些问题。鉴于下面的代码以及我命令事物工作的方式,我想知道更好的方法是使用 mysqli 方法。

是否有 mysqli 替代 mysql_num_rows 或者有不同的方法来计算所需的行数?

我如何使用 mysqli 执行以下操作?:

$data = mysql_query($countQuery) or die(mysql_error());
$rowcount = mysql_num_rows($data);

mysql_fetch_assoc 的替代方案是什么?我觉得我不应该使用我正在使用的当前行方法,即使有替换函数,那么正确的方法是什么?

我对这些问题表示歉意,但到目前为止我自己还无法确定答案。

<?php
$con = mysqli_connect("localhost", "user", "", "ebay");
if (!$con) {
echo "Can't connect to MySQL Server. Errorcode: %s\n". mysqli_connect_error();
exit;
}
$con->query("SET NAMES 'utf8'");
$cmd = "word";
//normally retrieved from GET
if($cmd=="deleterec") {
$deleteQuery = "DELETE FROM AUCTIONS1 WHERE ARTICLE_NO = ?";
if ($delRecord = $con->prepare($deleteQuery)) {
$delRecord->bind_param("s", $pk);
$delRecord->execute();
}
}
$table = 'AUCTIONS';
$brand = "test";
$countQuery = "SELECT ARTICLE_NO FROM ? WHERE upper(ARTICLE_NAME) LIKE '% ? %'";
if ($numRecords = $con->prepare($countQuery)) {
$numRecords->bind_param("ss", $table, $brand);
$numRecords->execute();
$data = $con->query($countQuery) or die(print_r($con->error));
$rowcount = mysql_num_rows($data);
$rows = getRowsByArticleSearch($query, $table, $max);
$last = ceil($rowcount/$page_rows);
}
$self = htmlspecialchars($_SERVER['PHP_SELF'],ENT_QUOTES,'utf-8');
foreach ($rows as $row) // print table rows {
echo '<tr>' . "\n";
echo '<td><a href="#" onclick="doThings(\'Layer2\', \'' . $pk . '\')">'.$row['USERNAME'].'</a></td>' . "\n";
// repeated for each column
}
function getRowsByArticleSearch($searchString, $table, $max) {
global $con;
$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 ? 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("ss", $searchString, $table);
$getRecords->execute();
$getRecords->bind_result($ARTICLE_NO, $USERNAME, $ACCESSSTARTS, $ARTICLE_NAME, $shortDate);
while ($getRecords->fetch()) {
$result = $con->query($recordsQuery);
$rows = array();
while($row = mysql_fetch_assoc($result)) {
$rows[] = $row;
}
return $rows;
}
}
}

最佳答案

我通常在执行后直接使用它:

 $query->execute();
// store the result first
$query->store_result();
$rows = $query->num_rows;

关于php - 使用 mysqli 计算行数并传递信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/598339/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com