Does anyone see anything wrong with this code?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
someguyhere
Forum Contributor
Posts: 181
Joined: Sun Jul 27, 2008 3:24 pm

Does anyone see anything wrong with this code?

Post by someguyhere »

Does anyone see anything wrong with this code?

Code: Select all

<?php

    $mysqli = new mysqli("localhost", "db", "pw", "user");
    $query = "SELECT ID FROM wp_posts WHERE post_title = 'some post'";
        $id = mysqli_query($mysqli, $query);
    echo var_dump($id);

?>
It returns:

Code: Select all


object(mysqli_result)#2 (0) { } 
In this case, the value in the DB is 993 and the field type is bigint
User avatar
DigitalMind
Forum Contributor
Posts: 152
Joined: Mon Sep 27, 2010 2:27 am
Location: Ukraine, Kharkov

Re: Does anyone see anything wrong with this code?

Post by DigitalMind »

Code: Select all

$query = "SELECT ID FROM wp_posts WHERE post_title = 'some post'";
$result = $mysqli->query($query);
while ($row = $result->fetch_assoc()) {
    echo $row['id'];
}
Post Reply