FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Problem with mysqli_stmt_bind_param()
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Problem with mysqli_stmt_bind_param() [message #179581 is a reply to message #179578] Fri, 09 November 2012 19:42 Go to previous messageGo to previous message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma:
Senior Member
On 11/9/2012 12:51 PM, rayven wrote:
>> On 11/8/2012 4:38 PM, rayven wrote:
>>> 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?
>>>
>>> Thanks in advance.
>>> Any responses posted here, or emailed to me directly will be very much appreciated.
>>>
>>>
>
>> What's in $myparam> echo it with delimiters around it (to ensure there
> i>s no extra white space) just before binding it.
>>
>> Does msqli_stmt_bind_param() return TRUE?
>> Do any of the rows in your table contain the value in $myparam?
>>
>> You need to do a bit of debugging here.
>>
>
> Way ahead of you I'm afraid.
> I have already echoed the parameter out to check the contents, made sure there are no leading or trailing spaces, checked the case or the parameter and checked teh database.
>
> I have even hard coded a $param='value'; into the page to make sure i knew it was correct, and like I said, I can search for the same data using mySQL Administrator and the record returns.
>
> What is worse, mysqli_stmt_bind_param() returns FALSE indicating an error, but when I ask for the error, nothing is being returned.
>

Please use the "Reply" button when responding to messages. That way the
thread will be maintained.

OK, so the bind is failing. Depending on the cause of the failure, it
may or may not show up as a MySQL error. On your test system ensure
that you have enabled all errors and are displaying them. Your php.ini
file should have:

error_reporting=E_ALL
display_errors=on

I suspect you'll get an error message with these settings.

Also - why are you mixing OO and non-OO methods?

$connection = new mysqli... is object oriented. The rest of your code
is non-OO. You need to decide on one or the other (I prefer OO, myself).


P.S. You do NOT want these set in a production environment.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Analista Programador PHP
Next Topic: Using += assignment recursively on an array w/o notice
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Nov 24 12:07:13 GMT 2024

Total time taken to generate the page: 0.08082 seconds