summaryrefslogtreecommitdiff
path: root/ext/mysqli/tests/mysqli_stmt_bind_param_check_param_no_change.phpt
blob: e7bce112af5c8e4bf4e27db2c9eb8b4ecf9a4b4d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
--TEST--
mysqli_stmt_bind_param() - checking whether the parameters are modified (bug#44390)
--SKIPIF--
<?php
require_once('skipif.inc');
require_once('skipifemb.inc');
require_once('skipifconnectfailure.inc');
?>
--FILE--
<?php
	require('table.inc');
	$link->set_charset('latin1');

	class foo {
	  // @var $bar string
	  public $bar;
	}

	$foo = new foo;
	$foo->bar = "фубар";

	echo "Test 1:\n";
	$stmt = $link->prepare("SELECT ? FOO");
	var_dump($foo); // here you can see the bar member var being a string
	$stmt->bind_param("s", $foo->bar);
	var_dump($foo); // this will show $foo->bar being a reference string
	$stmt->bind_result($one);
	$stmt->execute();
	$stmt->fetch();
	$stmt->free_result();
	echo("$one\n\n");

	// it is getting worse. Binding the same var twice with different
	// types you can get unexpected results (e.g. binary trash for the
	// string and misc data for the integer. See next 2 tests.

	echo "Test 2:\n";
	$stmt = $link->prepare("SELECT ? FOO, ? BAR");
	var_dump($foo);
	$stmt->bind_param("si", $foo->bar, $foo->bar);
	echo "---\n";
	var_dump($foo);
	echo "---\n";
	$stmt->execute();
	var_dump($foo);
	echo "---\n";
	$stmt->bind_result($one, $two);
	$stmt->fetch();
	$stmt->free_result();
	echo("$one - $two\n\n");


	echo "Test 3:\n";
	$stmt = $link->prepare("SELECT ? FOO, ? BAR");
	var_dump($foo);
	$stmt->bind_param("is", $foo->bar, $foo->bar);
	var_dump($foo);
	$stmt->bind_result($one, $two);
	$stmt->execute();
	$stmt->fetch();
	$stmt->free_result();
	echo("$one - $two\n\n");
	echo "done!";
?>
--CLEAN--
<?php
	require_once("clean_table.inc");
?>
--EXPECTF--
Test 1:
object(foo)#%d (1) {
  [%u|b%"bar"]=>
  %unicode|string%(%d) "фубар"
}
object(foo)#%d (1) {
  [%u|b%"bar"]=>
  &%unicode|string%(%d) "фубар"
}
фубар

Test 2:
object(foo)#%d (1) {
  [%u|b%"bar"]=>
  %unicode|string%(%d) "фубар"
}
---
object(foo)#%d (1) {
  [%u|b%"bar"]=>
  &%unicode|string%(%d) "фубар"
}
---
object(foo)#%d (1) {
  [%u|b%"bar"]=>
  &%unicode|string%(%d) "фубар"
}
---
фубар - 0

Test 3:
object(foo)#%d (1) {
  [%u|b%"bar"]=>
  %unicode|string%(%d) "фубар"
}
object(foo)#%d (1) {
  [%u|b%"bar"]=>
  &%unicode|string%(%d) "фубар"
}
0 - фубар

done!