Re: Problem with mysqli_stmt_bind_param() [message #179579 is a reply to message #179572] |
Fri, 09 November 2012 17:56 |
rayven
Messages: 3 Registered: November 2012
Karma:
|
Junior Member |
|
|
> Am 08.11.2012 22:38, schrieb rayven:
>> Can anyone help as I am at my wits end.
>> On my PHP page, the following code works perefectly:
>>
>> <?php
>> $connection = new mysqli("localhost", "...", "...", "...");
>> $sql="SELECT field1, field2 FROM mytable";
>> if($stmt = mysqli_prepare($connection, $sql))
>> {
>> mysqli_stmt_bind_param($stmt, "s", $emailaddress);
>> mysqli_stmt_execute($stmt);
>> mysqli_stmt_bind_result($stmt, $clientid, $siteadmin);
>> mysqli_stmt_fetch($stmt);
>> echo($clientid);
>> echo($siteadmin);
>> mysqli_stmt_close($stmt);
>> }
>> mysqli_close($connection);
>> ?>
>>
>> But the moment I introduce mysqli_stmt_bind_param() and a parameter on the SELECT statement, I get rows_affected = -1 and no error returned, and no data is returned either. But if I run the same statement with the same parameters (and I have checked the parameter variables are populated correctly) in the mysql administrator, it works!
>>
>> <?php
>> $connection = new mysqli("localhost", "...", "...", "...");
>> $sql="SELECT field1, field2 FROM mytable WHERE field3=?";
>> if($stmt = mysqli_prepare($connection, $sql))
>> {
>> mysqli_stmt_bind_param($stmt, "s", $myparam);
>> mysqli_stmt_execute($stmt);
>> mysqli_stmt_bind_result($stmt, $clientid, $siteadmin);
>> mysqli_stmt_fetch($stmt);
>> echo($clientid);
>> echo($siteadmin);
>> mysqli_stmt_close($stmt);
>> }
>> mysqli_close($connection);
>> ?>
>>
>> What on earth am I doing wrong?
> On my system (not mysql), I would enable full statement logging in the database and
> see what is sent.
> Another observation: your code is not very stable, the only time you check a return
> code is the prepare step. And you do not check the number of returned rows.
> Then style: I wonder why the OO style is not used, it is shorter to write and read.
> And you can extend mysqli and put your utility functions into it.
> But your problem seems to depend only on the values of your variables.
> /Str.
Sorry, I should have been a bit more precise.
The original code has full error checking and row count checking, I stripped all of that out just to show the statements I am using.
As mentioned to a previous poster, I have checked the values and parametyers carefully, that was the first thing I did. mysql_stmt_bind_params() is returning FALSE indicating that I have an error there, but when I ask for the error nothing is returned.
I can't enable logging as the database is on a hosted server that I have no control over.
And as for the OO style, that was my original approach but that wasn't working, which is why I swapped to the procedural style shown here, but the problem followed me.
I'll soldier on, I've had a night of sleep so hopefully I might spot something I have missed. I just hate it when something gets the better of me :)
Thanks for all your help anyway.
|
|
|