1--TEST-- 2Bug #44879 (failed to prepare statement) 3--SKIPIF-- 4<?php 5require_once('skipif.inc'); 6 7if (!stristr(mysqli_get_client_info(), 'mysqlnd')) 8 die("skip: only available in mysqlnd"); 9 10require_once('skipifconnectfailure.inc'); 11require_once('connect.inc'); 12 13if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) { 14 die(sprintf('skip Cannot connect to MySQL, [%d] %s.', mysqli_connect_errno(), mysqli_connect_error())); 15} 16if (mysqli_get_server_version($link) <= 50000) { 17 die(sprintf('skip Needs MySQL 5.0+, found version %d.', mysqli_get_server_version($link))); 18} 19?> 20--FILE-- 21<?php 22 require_once("table.inc"); 23 24 if (!$link->query('DROP PROCEDURE IF EXISTS p')) 25 printf("[001] [%d] %s\n", $link->errno, $link->error); 26 27 if (!$link->query('CREATE PROCEDURE p(IN new_id INT, IN new_label CHAR(1)) BEGIN INSERT INTO test(id, label) VALUES (new_id, new_label); SELECT new_label; END;')) 28 printf("[002] [%d] %s\n", $link->errno, $link->error); 29 30 $new_id = 100; 31 $new_label = 'z'; 32 33 if (!$stmt = $link->prepare('CALL p(?, ?)')) 34 printf("[003] [%d] %s\n", $link->errno, $link->error); 35 36 if (!$stmt->bind_param('is', $new_id, $new_label) || !$stmt->execute()) 37 printf("[004] [%d] %s\n", $stmt->errno, $stmt->error); 38 39 $out_new_label = null; 40 if (!$stmt->bind_result($out_new_label) || !$stmt->fetch()) 41 printf("[005] [%d] %s\n", $stmt->errno, $stmt->error); 42 43 if ($out_new_label != $new_label) 44 printf("[006] IN value and returned value differ. Expecting %s/%s got %s/%s\n", 45 $new_label, gettype($new_label), $out_new_label, gettype($out_new_label)); 46 47 $stmt->close(); 48 49 $stmt2 = $link->prepare('SELECT label FROM test WHERE id = ?'); 50 if (!is_object($stmt2)) { 51 52 printf("[007] Failed to create new statement object, [%d] %s\n", 53 $link->errno, $link->error); 54 55 } else { 56 57 if (!$stmt2->bind_param("i", $new_id) || !$stmt2->execute()) 58 printf("[008] [%d] %s\n", $stmt2->errno, $stmt2->error); 59 60 $out_new_label = null; 61 if (!$stmt2->bind_result($out_new_label) || !$stmt2->fetch()) 62 printf("[009] [%d] %s\n", $stmt2->errno, $stmt2->error); 63 64 if ($out_new_label != $new_label) 65 printf("[010] IN value and returned value differ. Expecting %s/%s got %s/%s\n", 66 $new_label, gettype($new_label), $out_new_label, gettype($out_new_label)); 67 68 } 69 70 $link->close(); 71 72 print "done!"; 73?> 74--CLEAN-- 75<?php 76require_once("connect.inc"); 77if (!$link = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) 78 printf("[c001] [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error()); 79 80if (!mysqli_query($link, "DROP TABLE IF EXISTS test")) 81 printf("[c002] Cannot drop table, [%d] %s\n", mysqli_errno($link), mysqli_error($link)); 82 83mysqli_query($link, "DROP PROCEDURE IF EXISTS p"); 84 85mysqli_close($link); 86?> 87--EXPECTF-- 88done! 89