Annotation of embedaddon/php/ext/pdo_sqlite/tests/pdo_fetch_func_001.phpt, revision 1.1
1.1 ! misho 1: --TEST--
! 2: Testing several callbacks using PDO::FETCH_FUNC
! 3: --SKIPIF--
! 4: <?php
! 5: if (!extension_loaded('pdo_sqlite')) print 'skip not loaded';
! 6: ?>
! 7: --FILE--
! 8: <?php
! 9:
! 10: $db = new PDO('sqlite::memory:');
! 11: $db->exec('CREATE TABLE testing (id INTEGER , name VARCHAR)');
! 12: $db->exec('INSERT INTO testing VALUES(1, "php")');
! 13: $db->exec('INSERT INTO testing VALUES(2, "")');
! 14:
! 15: $st = $db->query('SELECT * FROM testing');
! 16: $st->fetchAll(PDO::FETCH_FUNC, function($x, $y) use ($st) { var_dump($st); print "data: $x, $y\n"; });
! 17:
! 18: $st = $db->query('SELECT name FROM testing');
! 19: var_dump($st->fetchAll(PDO::FETCH_FUNC, 'strtoupper'));
! 20:
! 21: $st = $db->query('SELECT * FROM testing');
! 22: var_dump($st->fetchAll(PDO::FETCH_FUNC, 'nothing'));
! 23:
! 24: $st = $db->query('SELECT * FROM testing');
! 25: var_dump($st->fetchAll(PDO::FETCH_FUNC, ''));
! 26:
! 27: $st = $db->query('SELECT * FROM testing');
! 28: var_dump($st->fetchAll(PDO::FETCH_FUNC, NULL));
! 29:
! 30: $st = $db->query('SELECT * FROM testing');
! 31: var_dump($st->fetchAll(PDO::FETCH_FUNC, 1));
! 32:
! 33: $st = $db->query('SELECT * FROM testing');
! 34: var_dump($st->fetchAll(PDO::FETCH_FUNC, array('self', 'foo')));
! 35:
! 36: class foo {
! 37: public function foo($x) {
! 38: return "--- $x ---";
! 39: }
! 40: }
! 41: class bar extends foo {
! 42: public function __construct($db) {
! 43: $st = $db->query('SELECT * FROM testing');
! 44: var_dump($st->fetchAll(PDO::FETCH_FUNC, array($this, 'parent::foo')));
! 45: }
! 46:
! 47: static public function test($x, $y) {
! 48: return $x .'---'. $y;
! 49: }
! 50:
! 51: private function test2($x, $y) {
! 52: return $x;
! 53: }
! 54:
! 55: public function test3($x, $y) {
! 56: return $x .'==='. $y;
! 57: }
! 58: }
! 59:
! 60: new bar($db);
! 61:
! 62: $st = $db->query('SELECT * FROM testing');
! 63: var_dump($st->fetchAll(PDO::FETCH_FUNC, array('bar', 'test')));
! 64:
! 65: $st = $db->query('SELECT * FROM testing');
! 66: var_dump($st->fetchAll(PDO::FETCH_FUNC, array('bar', 'test2')));
! 67:
! 68: $st = $db->query('SELECT * FROM testing');
! 69: var_dump($st->fetchAll(PDO::FETCH_FUNC, array('bar', 'test3')));
! 70:
! 71: $st = $db->query('SELECT * FROM testing');
! 72: var_dump($st->fetchAll(PDO::FETCH_FUNC, array('bar', 'inexistent')));
! 73:
! 74: ?>
! 75: --EXPECTF--
! 76: object(PDOStatement)#%d (1) {
! 77: [%u|b%"queryString"]=>
! 78: %string|unicode%(21) "SELECT * FROM testing"
! 79: }
! 80: data: 1, php
! 81: object(PDOStatement)#%d (1) {
! 82: [%u|b%"queryString"]=>
! 83: %string|unicode%(21) "SELECT * FROM testing"
! 84: }
! 85: data: 2,
! 86: array(2) {
! 87: [0]=>
! 88: %string|unicode%(3) "PHP"
! 89: [1]=>
! 90: %string|unicode%(0) ""
! 91: }
! 92:
! 93: Warning: PDOStatement::fetchAll(): SQLSTATE[HY000]: General error: function 'nothing' not found or invalid function name in %s on line %d
! 94: bool(false)
! 95:
! 96: Warning: PDOStatement::fetchAll(): SQLSTATE[HY000]: General error: function '' not found or invalid function name in %s on line %d
! 97: bool(false)
! 98:
! 99: Warning: PDOStatement::fetchAll(): SQLSTATE[HY000]: General error: no array or string given in %s on line %d
! 100: bool(false)
! 101:
! 102: Warning: PDOStatement::fetchAll(): SQLSTATE[HY000]: General error: no array or string given in %s on line %d
! 103: bool(false)
! 104:
! 105: Warning: PDOStatement::fetchAll(): SQLSTATE[HY000]: General error: cannot access self:: when no class scope is active in %s on line %d
! 106: bool(false)
! 107: array(2) {
! 108: [0]=>
! 109: %string|unicode%(9) "--- 1 ---"
! 110: [1]=>
! 111: %string|unicode%(9) "--- 2 ---"
! 112: }
! 113: array(2) {
! 114: [0]=>
! 115: %string|unicode%(7) "1---php"
! 116: [1]=>
! 117: %string|unicode%(4) "2---"
! 118: }
! 119:
! 120: Warning: PDOStatement::fetchAll(): SQLSTATE[HY000]: General error: cannot access private method bar::test2() in %s on line %d
! 121: bool(false)
! 122: array(2) {
! 123: [0]=>
! 124: %string|unicode%(7) "1===php"
! 125: [1]=>
! 126: %string|unicode%(4) "2==="
! 127: }
! 128:
! 129: Warning: PDOStatement::fetchAll(): SQLSTATE[HY000]: General error: class 'bar' does not have a method 'inexistent' in %s on line %d
! 130: bool(false)
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>