|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2007-01-18 10:12 UTC] oliver dot klink at volksbank-rems dot de
[2007-01-18 10:25 UTC] tony2001@php.net
[2007-01-18 13:45 UTC] oliver dot klink at volksbank-rems dot de
[2007-01-18 14:01 UTC] tony2001@php.net
[2007-01-18 16:05 UTC] oliver dot klink at volksbank-rems dot de
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 06 20:00:02 2025 UTC |
Description: ------------ I try to use mysqli_stmt_bind_param with several elements of an array as parameters. But it seems that these parameters are not updated properly. In the sample code I initialize the var $data with two values. Otherwise I would get an error saying that the column is not allowed to be null, when I execute the statement. These start values should be overwritten by the values generated by the explode function. print_r shows that the array $data gets updated as expected while the values transmitted by mysqli_stmt_execute are not. If I place the mysqli_stmt_bind_param after the explode-command the script works as expected, but I think that's not how mysqli_stmt_bind_param is meant to be used. Reproduce code: --------------- <?php $dw = new mysqli("localhost", "****", "****", "testdb"); $dw->query("CREATE TABLE IF NOT EXISTS `test` ( `filiale` smallint(5) unsigned NOT NULL, `berater` smallint(5) unsigned NOT NULL, PRIMARY KEY (`filiale`) )"); $data = array(1,2); $test = array("10;123","20;456"); $stmt = $dw->prepare("INSERT INTO test (filiale, berater) VALUES (?,?)"); $stmt->bind_param("ii",$data[0],$data[1]); foreach ($test as $buffer) { $data = explode(";", $buffer); print_r($data); $stmt->execute(); echo $dw->error."<br> <br>"; } $stmt = null; $dw = null; ?> Expected result: ---------------- Array ( [0] => 10 [1] => 123 ) Array ( [0] => 20 [1] => 456 ) Actual result: -------------- Array ( [0] => 10 [1] => 123 ) Array ( [0] => 20 [1] => 456 ) Duplicate entry '1' for key 1