php-src/ext/mysql/tests/mysql_fetch_field.phpt

159 lines
2.9 KiB
PHP

--TEST--
mysql_fetch_field()
--SKIPIF--
<?php require_once('skipif.inc'); ?>
<?php require_once('skipifemb.inc'); ?>
--FILE--
<?php
include "connect.inc";
$tmp = NULL;
$link = NULL;
// Note: no SQL type tests, internally the same function gets used as for mysql_fetch_array() which does a lot of SQL type test
if (!is_null($tmp = @mysql_fetch_field()))
printf("[001] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
if (false !== ($tmp = @mysql_fetch_field($link)))
printf("[002] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
require('table.inc');
if (!$res = mysql_query("SELECT id AS ID, label FROM test AS TEST ORDER BY id LIMIT 1", $link)) {
printf("[003] [%d] %s\n", mysql_errno($link), mysql_error($link));
}
while ($tmp = mysql_fetch_field($res))
var_dump($tmp);
var_dump($tmp);
mysql_free_result($res);
if (false !== ($tmp = mysql_fetch_field($res)))
printf("[004] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
mysql_close($link);
print "done!";
?>
--EXPECTF--
object(stdClass)#%d (13) {
["name"]=>
string(2) "ID"
["table"]=>
string(4) "TEST"
["def"]=>
string(0) ""
["max_length"]=>
int(1)
["not_null"]=>
int(1)
["primary_key"]=>
int(1)
["multiple_key"]=>
int(0)
["unique_key"]=>
int(0)
["numeric"]=>
int(1)
["blob"]=>
int(0)
["type"]=>
string(3) "int"
["unsigned"]=>
int(0)
["zerofill"]=>
int(0)
}
object(stdClass)#%d (13) {
["name"]=>
string(5) "label"
["table"]=>
string(4) "TEST"
["def"]=>
string(0) ""
["max_length"]=>
int(1)
["not_null"]=>
int(0)
["primary_key"]=>
int(0)
["multiple_key"]=>
int(0)
["unique_key"]=>
int(0)
["numeric"]=>
int(0)
["blob"]=>
int(0)
["type"]=>
string(6) "string"
["unsigned"]=>
int(0)
["zerofill"]=>
int(0)
}
bool(false)
Warning: mysql_fetch_field(): %d is not a valid MySQL result resource in %s on line %d
done!
--UEXPECTF--
object(stdClass)#%d (13) {
[u"name"]=>
unicode(2) "ID"
[u"table"]=>
unicode(4) "TEST"
[u"def"]=>
unicode(0) ""
[u"max_length"]=>
int(1)
[u"not_null"]=>
int(1)
[u"primary_key"]=>
int(1)
[u"multiple_key"]=>
int(0)
[u"unique_key"]=>
int(0)
[u"numeric"]=>
int(1)
[u"blob"]=>
int(0)
[u"type"]=>
unicode(3) "int"
[u"unsigned"]=>
int(0)
[u"zerofill"]=>
int(0)
}
object(stdClass)#%d (13) {
[u"name"]=>
unicode(5) "label"
[u"table"]=>
unicode(4) "TEST"
[u"def"]=>
unicode(0) ""
[u"max_length"]=>
int(1)
[u"not_null"]=>
int(0)
[u"primary_key"]=>
int(0)
[u"multiple_key"]=>
int(0)
[u"unique_key"]=>
int(0)
[u"numeric"]=>
int(0)
[u"blob"]=>
int(0)
[u"type"]=>
unicode(6) "string"
[u"unsigned"]=>
int(0)
[u"zerofill"]=>
int(0)
}
bool(false)
Warning: mysql_fetch_field(): %d is not a valid MySQL result resource in %s on line %d
done!