Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.