|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2006-06-27 20:27 UTC] ibexris at gmail dot com
Description:
------------
Like the summary says... using a bound parameter inside of a CONCAT() produces strange results.
Reproduce code:
---------------
<?php
$dbh = mysqli_init();
$dbh->real_connect('localhost', 'dbuser', '', 'dbname');
$sh = $dbh->prepare('SELECT CONCAT("xxx", ?, "xxx"), CONCAT("xxx", "abc", "xxx")');
$sh->bind_param('s', $x);
$sh->bind_result($r, $r2);
$x = 'abc';
$sh->execute();
$sh->fetch();
echo "\n$r\n$r2\n\n";
$dbh->close();
Expected result:
----------------
xxxabcxxx
xxxabcxxx
Actual result:
--------------
On my system, this prints out:
xxxabcxA
xxxabcxxx
The "A" changes on other systems (or goes away). However, both lines *should* be the same. Change the x's around in the first field and watch the results get even stranger, or remove them completely to have it work as expected (except that I need the CONCAT for my query).
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 13:00:01 2025 UTC |
mysqli_bind_result has to be called after mysqli_stmt_execute, not before. $stmt = $mysql->prepare("SELECT CONCAT('xxx', ?, 'xxx') FROM DUAL"); $stmt->bind_param('s', $a); $a = "abc"; $stmt->execute(); $stmt->bind_result($concat); $stmt->fetch(); var_dump($concat); Result: string(9) "xxxabcxxx"Shouldn't php then throw an error at least a warning? The whole point of a function like this is to avoid extraneous data assignments. My initial desire to use it was like: prepare bind loop execute loop fetch [code] endloop endloop finish It's trivial to move the bind inside the first loop, but seems redundant. Nowhere in the documentation does it say that bind must be called after execute, and as you see, it *does* work, just doesn't work correctly.