Jump to content

MySQLi using limit and bind param problem?


chrisjroyce

Recommended Posts

<?php
$link = mysqli_connect("hostName", "user", "pass", "db");

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

$limit = 1;

/* create a prepared statement */
$stmt = $link->prepare('SELECT `id` FROM `proofImages` WHERE `clientId` = 1 LIMIT ?');

$stmt->bind_param('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);
?>

 

Whenever I try to bind a value to my query for the limit the query fails. I have no idea why, and if I remove the Limit everything works.

 

Any ideas? It's been driving me crazy for days!

I've read that it might be that MYSQL and PHP doesn't support prepared statement params for LIMITS

 

Fatal error: Call to a member function bind_param() on a non-object in /var/www/vhosts/domain.co.uk/subdomains/projects/httpdocs/imageViewer/limit.php on line 16

 

is the error message.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.