问题
Alright so this bugs the crap out of me, and I can't seem to find anything in the PHP documentation, nor anywhere in the Google resultosphere, so maybe someone can help here.
I am using prepared statements, binding the results, and then using those bound results to populate dropdown. Example:
<option value="">Select artist</option>
<?php
$artistQuery = "SELECT ArtistID,ArtistName FROM Artist_v";
if($artist = mysqli_prepare($link,$artistQuery)){
mysqli_stmt_execute($artist);
$artistResult = mysqli_stmt_bind_result($artist,$artistID,$artistName);
while(mysqli_stmt_fetch($artist)){
?>
<option value="<?php echo $artistID; ?>"><?php echo $artistName; ?></option>
<?php
}
mysqli_stmt_close($artist);
}
?>
<option value="Other">Add new...</option>
There is something you might notice is a little odd. Namely:
$artistResult = mysqli_stmt_bind_result($artist,$artistID,$artistName);
In the PHP documentation for mysqli_stmt_bind_result there is no reason whatsoever to capture this result into a variable, that something like this should be just fine:
mysqli_stmt_bind_result($artist,$artistID,$artistName);
Not only that, the variable that I use to capture the result is never used. The only reason I capture at all is because without performing this capture processing always fails. Like ... the rest of the page refuses to even be produced. I've checked mysqli_error(), error_reporting(E_ALL); ini_set('display_errors', '1');, all the error messaging you can think of ... nothing.
What's worse, my development box doesn't have this issue, nor did my previous hosting provider ... I encountered this first when I changed to my new provider. This tells me (a) my original PHP is just fine, and (b) it could be a settings / options issue. I just have no idea where.
Has anyone experienced this?
By the way, don't ask me how I arrived at the variable capture thing to get it working ... it was a multi-hour trial-and-error session, and I couldn't tell you what my thinking was for trying it.
回答1:
Okay this really isn't a bloody answer, but my problem has been solved.
Turns out that the implementation of version 5.4 is sh**ty or something, because I switched to having my site run off of version 5.3 and all of a sudden it worked.
Bottom line, I appreciate all the help that you guys offered, but I must force myself to use an older version of PHP for the time being at least. That's four days I'll never get back.
EDIT
I found a real solution: switch hosting providers. Haven't experienced this issue since.
来源:https://stackoverflow.com/questions/19438282/strange-issue-with-mysqli-stmt-bind-result