mysqli prepare query with limit?

Associate
Joined
23 Mar 2005
Posts
969
Location
Colchester, Essex
Can this be done?

Code:
<?php
$link = mysqli_connect("domain", "user", "password", "db");

/* check connection */
if (mysqli_connect_errno()) 
{
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

/* create a prepared statement */
if ($stmt = mysqli_prepare($link, "SELECT `id` FROM `proofImages` WHERE `clientId` = 1 LIMIT 0, ? ")) 
{
	
	$limit = 10;
    /* bind parameters for markers */
    mysqli_stmt_bind_param($stmt, "i", $limit);

    /* execute query */
    $stmt->execute();

    /* bind result variables */
    $stmt->bind_result($col1);

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

    /* close statement */
    mysqli_stmt_close($stmt);
}

/* close connection */
mysqli_close($link);
?>

This does not work, if I hard code the limit it works fine. I get no errors in the log anywhere?

Any ideas?
 
Back
Top Bottom