tags:

views:

76

answers:

2

Not working:

$link = mysqli_connect("localhost", "********", "*******", "*******");
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

$cmp = 126;
if (($stmt = mysqli_prepare($link, "SELECT datalock FROM sys_tenancy WHERE id=?"))) {
    echo mysqli_stmt_bind_param($stmt, "i", $cmp) ? '1':'0';
    echo mysqli_stmt_execute($stmt) ? '1':'0';
    echo mysqli_stmt_bind_result($stmt, $datalock) ? '1':'0';
    echo mysqli_stmt_fetch($stmt) ? '1':'0';

    printf("%s: %s\n", $cmp, $datalock);

    mysqli_stmt_close($stmt);
}
mysqli_close($link);

output:

1110 126: 0

Working:

$link = mysqli_connect("localhost", "********", "*******", "*******");
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}

//$cmp = 126;
if (($stmt = mysqli_prepare($link, "SELECT datalock FROM sys_tenancy WHERE id=126"))) {
    //echo mysqli_stmt_bind_param($stmt, "i", $cmp) ? '1':'0';
    echo mysqli_stmt_execute($stmt) ? '1':'0';
    echo mysqli_stmt_bind_result($stmt, $datalock) ? '1':'0';
    echo mysqli_stmt_fetch($stmt) ? '1':'0';

    printf(" %s: %s\n", $cmp, $datalock);

    mysqli_stmt_close($stmt);
}
mysqli_close($link);

output:

111 126: 1

What I need is the first one to work. I have mysql 4.1.22 and php 5.2.13

+1  A: 

If you want to know what the error is rather than just the fact an error occurred, change:

echo mysqli_stmt_fetch($stmt) ? '1':'0';

to:

echo mysqli_stmt_fetch($stmt) ? '1':'0';
printf ("Error: %s\n", mysqli_stmt_error($stmt));

That should hopefully tell you why it's not working.

paxdiablo
You might also want to check whether the return value is false (=error) or null (=no more rows).
che
Already did that, there was no error. The return value was null.
Patrick
A: 

I want to close this question, I'm going with regular mysql functions for now until the server guys find a way to get the latest everything up there.

Patrick