|
| 1 | +--TEST-- |
| 2 | +mysqli_stmt_execute() - bind in execute |
| 3 | +--SKIPIF-- |
| 4 | +<?php |
| 5 | +require_once('skipif.inc'); |
| 6 | +require_once('skipifconnectfailure.inc'); |
| 7 | +if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) { |
| 8 | + die(sprintf('skip Cannot connect to MySQL, [%d] %s.', mysqli_connect_errno(), mysqli_connect_error())); |
| 9 | +} |
| 10 | +if (mysqli_get_server_version($link) <= 40100) { |
| 11 | + die(sprintf('skip Needs MySQL 4.1+, found version %d.', mysqli_get_server_version($link))); |
| 12 | +} |
| 13 | +if (stristr(mysqli_get_client_info(), 'mysqlnd')) { |
| 14 | + die("skip: only applicable for libmysqlclient"); |
| 15 | +} |
| 16 | +?> |
| 17 | +--FILE-- |
| 18 | +<?php |
| 19 | + require_once("connect.inc"); |
| 20 | + |
| 21 | + require('table.inc'); |
| 22 | + |
| 23 | + mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); |
| 24 | + |
| 25 | + // first, control case |
| 26 | + $id = 1; |
| 27 | + $abc = 'abc'; |
| 28 | + $stmt = $link->prepare('SELECT label, ? AS anon, ? AS num FROM test WHERE id=?'); |
| 29 | + $stmt->bind_param('sss', ...[&$abc, 42, $id]); |
| 30 | + $stmt->execute(); |
| 31 | + assert($stmt->get_result()->fetch_assoc() === ['label'=>'a', 'anon'=>'abc', 'num' => '42']); |
| 32 | + $stmt = null; |
| 33 | + |
| 34 | + // 1. same as the control case, but skipping the middle-man (bind_param) |
| 35 | + $stmt = $link->prepare('SELECT label, ? AS anon, ? AS num FROM test WHERE id=?'); |
| 36 | + try { |
| 37 | + $stmt->execute([&$abc, 42, $id]); |
| 38 | + } catch (ArgumentCountError $e) { |
| 39 | + echo '[001] '.$e->getMessage()."\n"; |
| 40 | + } |
| 41 | + $stmt = null; |
| 42 | + |
| 43 | + mysqli_close($link); |
| 44 | + print "done!"; |
| 45 | +?> |
| 46 | +--CLEAN-- |
| 47 | +<?php |
| 48 | + require_once("clean_table.inc"); |
| 49 | +?> |
| 50 | +--EXPECT-- |
| 51 | +[001] Binding parameters in execute is not supported with libmysqlclient |
| 52 | +done! |
0 commit comments