PHP mysqli statement bind result


mysqli connect, prepare, execute, bind result, fetch, close

connect
include 'connect.php';

$mysqli = new mysqli("localhost", $user, $passwd, $db);

$errno = mysqli_connect_errno();

if ($errno) {
    printf("Connect failed: %s\n", mysqli_connect_error());
}


prepare
if (!$errno) {
    $query = "select id,tag,`time`,left(body,10) from wikka_pages limit 10";

    $stmt = $mysqli->prepare($query);

    $errno = $mysqli->errno;
}

if ($errno) {
    printf("SQL failed: %s\n", $mysqli->error);
}


execute
if (!$errno) {
    $stmt->execute();


bind result
    /* bind result variables */
    $stmt->bind_result($id,$tag,$date,$body);


fetch
    /* fetch values */
    while ($stmt->fetch()) {
        printf ("%s %s %s %s\n", $id, $tag, $date, $body);
    }
}


close
@$stmt->close();

@$mysqli->close();



REFERRERS
PhpMySqlDatabases
Valid XHTML :: Valid CSS: :: Powered by WikkaWiki