我正在努力将MySQL_Results替换为mysqli,有人能帮忙吗?我所需要的只是更正下面代码中的‘mysqli_Result($Result,’0‘,’theurl‘)。当使用MySQL函数编写所有东西时,它都能工作。但是,在我将所有内容转换为mysqli之后,MySQL_Results转换似乎就不起作用了。
当它工作时:echo(mysql_num_rows($query) !== 0) ? mysql_result($query, 0, 'theurl') : 'None';
当我运行当前代码时,我得到一个错误:Fatal error: Call to a member function data_seek() on a non-object in /home/abc/abc/test.php on line 15
<?php
$getVal = "Record1";
require '../db/connect.php';
$query = ("SELECT 'photos'.'theurl' FROM 'photos' WHERE 'photos'.'thename' = '" . $getVal . "'");
$result = mysqli_query($conn_db, $query);
$queryA = ("SELECT id FROM photos");
$resultA = mysqli_query($conn_db, $queryA);
$row_cnt = $resultA->num_rows;
echo($row_cnt !== 0) ? mysqli_result($result, '0', 'theurl') : 'Not found.'; // syntax meaning:: echo condition ? if TRUE output : if FALSE output;
function mysqli_result($result, $ro, $field) {
$result->data_seek($ro);
$datarow = $result->fetch_array();
return $datarow[$field];
}
?>
I think that you have a query error, you are using incorrect quote types, you will try:
$query = ("SELECT `photos`.`theurl` FROM `photos` WHERE `photos`.`thename` = '" . $getVal . "'") or die(mysqli_error($conn_db));
And, if you have a query problem, you can't get any result later.