Page 1 of 1

Does anyone see anything wrong with this code?

Posted: Sat Feb 26, 2011 10:10 am
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

Re: Does anyone see anything wrong with this code?

Posted: Sat Feb 26, 2011 10:45 am
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'];
}