xref: /PHP-5.4/ext/mysql/tests/003.phpt (revision 610c7fbe)
1--TEST--
2mysql_fetch_object
3--SKIPIF--
4<?php
5require_once('skipif.inc');
6require_once('skipifconnectfailure.inc');
7?>
8--FILE--
9<?php
10include_once('connect.inc');
11
12class class24 {
13	function __construct() {
14		echo __METHOD__ . "\n";
15	}
16}
17
18$data = array("one", "two", "three");
19
20if (!$link = my_mysql_connect($host, $user, $passwd, $db, $port, $socket))
21	printf("[001] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
22		$host, $user, $db, $port, $socket);
23
24if (!mysql_query('DROP TABLE IF EXISTS test', $link))
25	printf("[002] [%d] %s\n", mysql_errno($link), mysql_error($link));
26
27if (!mysql_query("CREATE TABLE test(a varchar(10))", $link))
28	printf("[003] [%d] %s\n", mysql_errno($link), mysql_error($link));
29
30foreach ($data as $str) {
31	if (!mysql_query(sprintf("INSERT INTO test VALUES('%s')", $str), $link))
32		printf("[004 - %s] [%d] %s\n", $str, mysql_errno($link), mysql_error($link));
33}
34
35echo "==stdClass==\n";
36if (!$res = mysql_query("SELECT a FROM test", $link))
37	printf("[005] [%d] %s\n", mysql_errno($link), mysql_error($link));
38
39while ($obj = mysql_fetch_object($res)) {
40	var_dump($obj);
41}
42mysql_free_result($res);
43
44echo "==class24==\n";
45if (!$res = mysql_query("SELECT a FROM test", $link))
46    printf("[006] [%d] %s\n", mysql_errno($link), mysql_error($link));
47
48while ($obj = mysql_fetch_object($res, 'class24')) {
49	var_dump($obj);
50}
51mysql_free_result($res);
52mysql_close($link);
53print "done!";
54?>
55--CLEAN--
56<?php
57require_once("clean_table.inc");
58?>
59--EXPECTF--
60==stdClass==
61object(stdClass)#%d (1) {
62  [%u|b%"a"]=>
63  %unicode|string%(3) "one"
64}
65object(stdClass)#%d (1) {
66  [%u|b%"a"]=>
67  %unicode|string%(3) "two"
68}
69object(stdClass)#%d (1) {
70  [%u|b%"a"]=>
71  %unicode|string%(5) "three"
72}
73==class24==
74class24::__construct
75object(class24)#%d (1) {
76  [%u|b%"a"]=>
77  %unicode|string%(3) "one"
78}
79class24::__construct
80object(class24)#%d (1) {
81  [%u|b%"a"]=>
82  %unicode|string%(3) "two"
83}
84class24::__construct
85object(class24)#%d (1) {
86  [%u|b%"a"]=>
87  %unicode|string%(5) "three"
88}
89done!
90