xref: /PHP-5.5/ext/mysql/tests/003.phpt (revision b7091aaf)
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--
60Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in %s on line %d
61==stdClass==
62object(stdClass)#%d (1) {
63  [%u|b%"a"]=>
64  %unicode|string%(3) "one"
65}
66object(stdClass)#%d (1) {
67  [%u|b%"a"]=>
68  %unicode|string%(3) "two"
69}
70object(stdClass)#%d (1) {
71  [%u|b%"a"]=>
72  %unicode|string%(5) "three"
73}
74==class24==
75class24::__construct
76object(class24)#%d (1) {
77  [%u|b%"a"]=>
78  %unicode|string%(3) "one"
79}
80class24::__construct
81object(class24)#%d (1) {
82  [%u|b%"a"]=>
83  %unicode|string%(3) "two"
84}
85class24::__construct
86object(class24)#%d (1) {
87  [%u|b%"a"]=>
88  %unicode|string%(5) "three"
89}
90done!
91