Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #7503 > unrolled thread
| Started by | rayven <rayven@blueyonder.co.uk> |
|---|---|
| First post | 2012-11-08 15:38 -0600 |
| Last post | 2012-11-09 09:51 +0100 |
| Articles | 3 — 3 participants |
Back to article view | Back to comp.lang.php
Problem with mysqli_stmt_bind_param() rayven <rayven@blueyonder.co.uk> - 2012-11-08 15:38 -0600
Re: Problem with mysqli_stmt_bind_param() Jerry Stuckle <jstucklex@attglobal.net> - 2012-11-08 19:12 -0500
Re: Problem with mysqli_stmt_bind_param() "M. Strobel" <sorry_no_mail_here@nowhere.dee> - 2012-11-09 09:51 +0100
| From | rayven <rayven@blueyonder.co.uk> |
|---|---|
| Date | 2012-11-08 15:38 -0600 |
| Subject | Problem with mysqli_stmt_bind_param() |
| Message-ID | <_vOdnZvEQpjeuwHNnZ2dnUVZ7q6dnZ2d@giganews.com> |
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.
[toc] | [next] | [standalone]
| From | Jerry Stuckle <jstucklex@attglobal.net> |
|---|---|
| Date | 2012-11-08 19:12 -0500 |
| Message-ID | <k7hhor$m9q$1@dont-email.me> |
| In reply to | #7503 |
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
is 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.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
[toc] | [prev] | [next] | [standalone]
| From | "M. Strobel" <sorry_no_mail_here@nowhere.dee> |
|---|---|
| Date | 2012-11-09 09:51 +0100 |
| Message-ID | <ag3ugiFk2glU1@mid.uni-berlin.de> |
| In reply to | #7503 |
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.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.php
csiph-web