0
I’m having very specific problems while working on my crud. I created in the database a field called id, type INT and A_I and try to call it through this part of the code, but it keeps giving this error: Notice: Object of class mysqli_result could not be converted to int in C: xampp htdocs public_html inc database.php on line 25
$database = open_database();
$found = null;
try {
if ($id) {
$sql = "SELECT * FROM " . $table . " WHERE id = " . $id;
$result = $database->query($sql);
if ($result > 0) {
$found = $result->fetch_assoc();
}
} else {
$sql = "SELECT * FROM " . $table;
$result = $database->query($sql);
if ($result > 0) {´´´
já pesquisei p caramba porém não vejo oq está errado
if ($result > 0)
, you’re comparing an objectmysqli_result
with an integer; this makes no sense. If you want to check if you have returned any lines, you need to use thenum_rows
.– Woss
gives a
count
in the$result
.– Kayo Bruno