Annotation of embedaddon/php/ext/mysqli/tests/mysqli_stmt_bind_param_call_user_func.phpt, revision 1.1.1.1

1.1       misho       1: --TEST--
                      2: mysqli_stmt_bind_param used with call_user_func_array() (see also bug #43568)
                      3: --SKIPIF--
                      4: <?php
                      5: require_once('skipif.inc');
                      6: require_once('skipifemb.inc');
                      7: require_once('skipifconnectfailure.inc');
                      8: 
                      9: // TODO remove once a decision has been made on call_user_func_array()
                     10: if (version_compare(PHP_VERSION, '5.3.0-dev') == -1)
                     11:        die("skip needs PHP 5.3.0-dev+, see http://bugs.php.net/bug.php?id=43568");
                     12: ?>
                     13: --FILE--
                     14: <?php
                     15:        require('connect.inc');
                     16:        require('table.inc');
                     17: 
                     18:        if (!$stmt = mysqli_stmt_init($link))
                     19:                printf("[001] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
                     20: 
                     21:        if (!mysqli_stmt_prepare($stmt, 'SELECT id, label FROM test WHERE id = ?'))
                     22:                printf("[002] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
                     23: 
                     24:        $id = 1;
                     25:        if (!mysqli_stmt_bind_param($stmt, 'i', $id) ||
                     26:                !mysqli_stmt_execute($stmt))
                     27:                printf("[003] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
                     28: 
                     29:        $id = $label = null;
                     30:        if (!mysqli_stmt_bind_result($stmt, $id, $label) ||
                     31:                (true !== mysqli_stmt_fetch($stmt)))
                     32:                printf("[004] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
                     33: 
                     34:        print "Regular, procedural, using variables\n";
                     35:        var_dump($id);
                     36:        var_dump($label);
                     37: 
                     38:        mysqli_stmt_close($stmt);
                     39:        if (!$stmt = mysqli_stmt_init($link))
                     40:                printf("[005] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
                     41: 
                     42:        if (!mysqli_stmt_prepare($stmt, 'SELECT id, label FROM test WHERE id = ?'))
                     43:                printf("[006] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
                     44: 
                     45:        $types = 'i';
                     46:        $id = 1;
                     47:        $params = array(
                     48:                0 => &$stmt,
                     49:                1 => &$types,
                     50:                2 => &$id
                     51:        );
                     52:        if (!call_user_func_array('mysqli_stmt_bind_param', $params))
                     53:                printf("[007] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
                     54: 
                     55:        if (!mysqli_stmt_execute($stmt))
                     56:                printf("[008] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
                     57: 
                     58:        $id = $label = null;
                     59:        if (!mysqli_stmt_bind_result($stmt, $id, $label) ||
                     60:                (true !== mysqli_stmt_fetch($stmt)))
                     61:                printf("[009] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
                     62: 
                     63:        print "Call user func, procedural, using references for everything\n";
                     64:        var_dump($id);
                     65:        var_dump($label);
                     66: 
                     67:        mysqli_stmt_close($stmt);
                     68:        if (!$stmt = mysqli_stmt_init($link))
                     69:                printf("[010] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
                     70: 
                     71:        if (!mysqli_stmt_prepare($stmt, 'SELECT id, label FROM test WHERE id = ?'))
                     72:                printf("[011] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
                     73: 
                     74:        $types = 'i';
                     75:        $id = 1;
                     76:        $params = array(
                     77:                0 => &$types,
                     78:                1 => &$id
                     79:        );
                     80:        if (!call_user_func_array(array($stmt, 'bind_param'), $params))
                     81:                printf("[012] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
                     82: 
                     83:        if (!mysqli_stmt_execute($stmt))
                     84:                printf("[013] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
                     85: 
                     86:        $id = $label = null;
                     87:        if (!mysqli_stmt_bind_result($stmt, $id, $label) ||
                     88:                (true !== mysqli_stmt_fetch($stmt)))
                     89:                printf("[014] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
                     90: 
                     91:        print "Call user func, object oriented, using references for everything\n";
                     92:        var_dump($id);
                     93:        var_dump($label);
                     94: 
                     95:        mysqli_stmt_close($stmt);
                     96:        if (!$stmt = mysqli_stmt_init($link))
                     97:                printf("[015] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
                     98: 
                     99:        if (!mysqli_stmt_prepare($stmt, 'SELECT id, label FROM test WHERE id = ?'))
                    100:                printf("[016] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
                    101: 
                    102:        $types = 'i';
                    103:        $id = 1;
                    104:        $params = array(
                    105:                0 => $types,
                    106:                1 => &$id
                    107:        );
                    108:        if (!call_user_func_array(array($stmt, 'bind_param'), $params))
                    109:                printf("[017] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
                    110: 
                    111:        if (!mysqli_stmt_execute($stmt))
                    112:                printf("[018] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
                    113: 
                    114:        $id = $label = null;
                    115:        if (!mysqli_stmt_bind_result($stmt, $id, $label) ||
                    116:                (true !== mysqli_stmt_fetch($stmt)))
                    117:                printf("[019] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
                    118: 
                    119:        print "Call user func, object oriented, using variable for types. using references for bound parameter\n";
                    120:        var_dump($id);
                    121:        var_dump($label);
                    122: 
                    123:        mysqli_stmt_close($stmt);
                    124:        if (!$stmt = mysqli_stmt_init($link))
                    125:                printf("[020] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
                    126: 
                    127:        if (!mysqli_stmt_prepare($stmt, 'SELECT id, label FROM test WHERE id = ?'))
                    128:                printf("[021] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
                    129: 
                    130:        $id = 1;
                    131:        $params = array(
                    132:                0 => 'i',
                    133:                1 => &$id
                    134:        );
                    135:        if (!call_user_func_array(array($stmt, 'bind_param'), $params))
                    136:                printf("[022] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
                    137: 
                    138:        if (!mysqli_stmt_execute($stmt))
                    139:                printf("[023] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
                    140: 
                    141:        $id = $label = null;
                    142:        if (!mysqli_stmt_bind_result($stmt, $id, $label) ||
                    143:                (true !== mysqli_stmt_fetch($stmt)))
                    144:                printf("[024] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
                    145: 
                    146:        print "Call user func, object oriented, using constant for types. using references for bound parameter\n";
                    147:        var_dump($id);
                    148:        var_dump($label);
                    149: 
                    150:        mysqli_stmt_close($stmt);
                    151:        if (!$stmt = mysqli_stmt_init($link))
                    152:                printf("[025] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
                    153: 
                    154:        if (!mysqli_stmt_prepare($stmt, 'SELECT id, label FROM test WHERE id = ?'))
                    155:                printf("[026] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
                    156: 
                    157:        $types = 'i';
                    158:        $id = 1;
                    159:        $params = array(
                    160:                0 => &$stmt,
                    161:                1 => $types,
                    162:                2 => &$id
                    163:        );
                    164:        if (!call_user_func_array('mysqli_stmt_bind_param', $params))
                    165:                printf("[027] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
                    166: 
                    167:        if (!mysqli_stmt_execute($stmt))
                    168:                printf("[028] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
                    169: 
                    170:        $id = $label = null;
                    171:        if (!mysqli_stmt_bind_result($stmt, $id, $label) ||
                    172:                (true !== mysqli_stmt_fetch($stmt)))
                    173:                printf("[029] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
                    174: 
                    175:        print "Call user func, procedural, using references for everything but using variable for types\n";
                    176:        var_dump($id);
                    177:        var_dump($label);
                    178: 
                    179:        mysqli_stmt_close($stmt);
                    180:        if (!$stmt = mysqli_stmt_init($link))
                    181:                printf("[025] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
                    182: 
                    183:        if (!mysqli_stmt_prepare($stmt, 'SELECT id, label FROM test WHERE id = ?'))
                    184:                printf("[026] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
                    185: 
                    186:        $types = 'i';
                    187:        $id = 1;
                    188:        $params = array(
                    189:                0 => $stmt,
                    190:                1 => $types,
                    191:                2 => &$id
                    192:        );
                    193:        if (!call_user_func_array('mysqli_stmt_bind_param', $params))
                    194:                printf("[027] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
                    195: 
                    196:        if (!mysqli_stmt_execute($stmt))
                    197:                printf("[028] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
                    198: 
                    199:        $id = $label = null;
                    200:        if (!mysqli_stmt_bind_result($stmt, $id, $label) ||
                    201:                (true !== mysqli_stmt_fetch($stmt)))
                    202:                printf("[029] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
                    203: 
                    204:        print "Call user func, procedural, using references for bound parameter, using variables for resource and types\n";
                    205:        var_dump($id);
                    206:        var_dump($label);
                    207: 
                    208:        mysqli_stmt_close($stmt);
                    209:        if (!$stmt = mysqli_stmt_init($link))
                    210:                printf("[030] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
                    211: 
                    212:        if (!mysqli_stmt_prepare($stmt, 'SELECT id, label FROM test WHERE id = ?'))
                    213:                printf("[031] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
                    214: 
                    215:        $types = 'i';
                    216:        $id = 1;
                    217:        $params = array(
                    218:                0 => $stmt,
                    219:                1 => $types,
                    220:                2 => &$id
                    221:        );
                    222:        if (!call_user_func_array('mysqli_stmt_bind_param', $params))
                    223:                printf("[032] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
                    224: 
                    225:        if (!mysqli_stmt_execute($stmt))
                    226:                printf("[033] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
                    227: 
                    228:        $id = $label = null;
                    229:        if (!mysqli_stmt_bind_result($stmt, $id, $label) ||
                    230:                (true !== mysqli_stmt_fetch($stmt)))
                    231:                printf("[034] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
                    232: 
                    233:        print "Call user func, procedural, using references for bound parameter, using variables for resource and types\n";
                    234:        var_dump($id);
                    235:        var_dump($label);
                    236: 
                    237:        mysqli_stmt_close($stmt);
                    238:        if (!$stmt = mysqli_stmt_init($link))
                    239:                printf("[035] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
                    240: 
                    241:        if (!mysqli_stmt_prepare($stmt, 'SELECT id, label FROM test WHERE id = ?'))
                    242:                printf("[036] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
                    243: 
                    244:        $id = 1;
                    245:        $params = array(
                    246:                0 => $stmt,
                    247:                1 => 'i',
                    248:                2 => &$id
                    249:        );
                    250:        if (!call_user_func_array('mysqli_stmt_bind_param', $params))
                    251:                printf("[037] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
                    252: 
                    253:        if (!mysqli_stmt_execute($stmt))
                    254:                printf("[038] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
                    255: 
                    256:        $id = $label = null;
                    257:        if (!mysqli_stmt_bind_result($stmt, $id, $label) ||
                    258:                (true !== mysqli_stmt_fetch($stmt)))
                    259:                printf("[039] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
                    260: 
                    261:        print "Call user func, procedural, using references for bound parameter, using variable for resource, using constant for types\n";
                    262:        var_dump($id);
                    263:        var_dump($label);
                    264: 
                    265:        mysqli_stmt_close($stmt);
                    266:        if (!$stmt = mysqli_stmt_init($link))
                    267:                printf("[040] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
                    268: 
                    269:        if (!mysqli_stmt_prepare($stmt, 'SELECT id, label FROM test WHERE id = ?'))
                    270:                printf("[041] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
                    271: 
                    272:        $id = 1;
                    273:        if (!call_user_func_array('mysqli_stmt_bind_param', array($stmt, 'i', &$id)))
                    274:                printf("[042] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
                    275: 
                    276:        if (!mysqli_stmt_execute($stmt))
                    277:                printf("[043] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
                    278: 
                    279:        $id = $label = null;
                    280:        if (!mysqli_stmt_bind_result($stmt, $id, $label) ||
                    281:                (true !== mysqli_stmt_fetch($stmt)))
                    282:                printf("[044] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
                    283: 
                    284:        print "Call user func, procedural, using references for bound parameter, using variable for resource, using constant for types, array\n";
                    285:        var_dump($id);
                    286:        var_dump($label);
                    287: 
                    288:        //
                    289:        // Any of those shall fail - see also bugs.php.net/43568
                    290:        //
                    291:        mysqli_stmt_close($stmt);
                    292:        if (!$stmt = mysqli_stmt_init($link))
                    293:                printf("[045] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
                    294: 
                    295:        if (!mysqli_stmt_prepare($stmt, 'SELECT id, label FROM test WHERE id = ?'))
                    296:                printf("[046] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
                    297: 
                    298:        $id = 1;
                    299:        $params = array(
                    300:                0 => 'i',
                    301:                1 => &$id
                    302:        );
                    303:        if (!call_user_func_array(array($stmt, 'bind_param'), $params))
                    304:                printf("[047] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
                    305: 
                    306:        if (!mysqli_stmt_execute($stmt))
                    307:                printf("[048] [%d] (Message might vary with MySQL Server version, e.g. No data supplied for parameters in prepared statement)\n", mysqli_stmt_errno($stmt));
                    308: 
                    309:        mysqli_stmt_close($stmt);
                    310:        if (!$stmt = mysqli_stmt_init($link))
                    311:                printf("[049] [%d] %s\n", mysqli_errno($link), mysqli_error($link));
                    312: 
                    313:        if (!mysqli_stmt_prepare($stmt, 'SELECT id, label FROM test WHERE id = ?'))
                    314:                printf("[050] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
                    315: 
                    316:        $types = 'i';
                    317:        $id = 1;
                    318:        $params = array(
                    319:                0 => $stmt,
                    320:                1 => 'i',
                    321:                2 => &$id
                    322:        );
                    323:        if (!call_user_func_array('mysqli_stmt_bind_param', $params))
                    324:                printf("[051] [%d] %s\n", mysqli_stmt_errno($stmt), mysqli_stmt_error($stmt));
                    325: 
                    326:        if (!mysqli_stmt_execute($stmt))
                    327:                printf("[052] [%d] (Message might vary with MySQL Server version, e.g. No data supplied for parameters in prepared statement)\n", mysqli_stmt_errno($stmt));
                    328: 
                    329:        print "done!";
                    330: ?>
                    331: --CLEAN--
                    332: <?php
                    333:        require_once("clean_table.inc");
                    334: ?>
                    335: --EXPECTF--
                    336: Regular, procedural, using variables
                    337: int(1)
                    338: %unicode|string%(1) "a"
                    339: Call user func, procedural, using references for everything
                    340: int(1)
                    341: %unicode|string%(1) "a"
                    342: Call user func, object oriented, using references for everything
                    343: int(1)
                    344: %unicode|string%(1) "a"
                    345: Call user func, object oriented, using variable for types. using references for bound parameter
                    346: int(1)
                    347: %unicode|string%(1) "a"
                    348: Call user func, object oriented, using constant for types. using references for bound parameter
                    349: int(1)
                    350: %unicode|string%(1) "a"
                    351: Call user func, procedural, using references for everything but using variable for types
                    352: int(1)
                    353: %unicode|string%(1) "a"
                    354: Call user func, procedural, using references for bound parameter, using variables for resource and types
                    355: int(1)
                    356: %unicode|string%(1) "a"
                    357: Call user func, procedural, using references for bound parameter, using variables for resource and types
                    358: int(1)
                    359: %unicode|string%(1) "a"
                    360: Call user func, procedural, using references for bound parameter, using variable for resource, using constant for types
                    361: int(1)
                    362: %unicode|string%(1) "a"
                    363: Call user func, procedural, using references for bound parameter, using variable for resource, using constant for types, array
                    364: int(1)
                    365: %unicode|string%(1) "a"
                    366: done!

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>