Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!fu-berlin.de!uni-berlin.de!not-for-mail From: "M. Strobel" Newsgroups: comp.lang.php Subject: Re: Problem with mysqli_stmt_bind_param() Date: Fri, 09 Nov 2012 09:51:30 +0100 Lines: 52 Message-ID: References: <_vOdnZvEQpjeuwHNnZ2dnUVZ7q6dnZ2d@giganews.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Trace: news.uni-berlin.de BO+ySk9AdfPTfSxSMlRjYwUtdlmehBqJ2nCq7JIfNLmv1g9MDqioXk8jYgS30KXEA= User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:16.0) Gecko/20121025 Thunderbird/16.0.2 In-Reply-To: <_vOdnZvEQpjeuwHNnZ2dnUVZ7q6dnZ2d@giganews.com> Xref: csiph.com comp.lang.php:7507 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: > > $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! > > $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.