栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Mysqli get_result替代

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Mysqli get_result替代

这是基于相同原理的更整洁的解决方案:

function get_result( $Statement ) {    $RESULT = array();    $Statement->store_result();    for ( $i = 0; $i < $Statement->num_rows; $i++ ) {        $metadata = $Statement->result_metadata();        $PARAMS = array();        while ( $Field = $metadata->fetch_field() ) { $PARAMS[] = &$RESULT[ $i ][ $Field->name ];        }        call_user_func_array( array( $Statement, 'bind_result' ), $PARAMS );        $Statement->fetch();    }    return $RESULT;}

使用mysqlnd, 您通常可以执行以下操作:

$Statement = $Database->prepare( 'SELECt x FROM y WHERe z = ?' );$Statement->bind_param( 's', $z );$Statement->execute();$Result = $Statement->get_result();while ( $DATA = $Result->fetch_array() ) {    // Do stuff with the data}

而且 没有mysqlnd

$Statement = $Database->prepare( 'SELECt x FROM y WHERe z = ?' );$Statement->bind_param( 's', $z );$Statement->execute();$RESULT = get_result( $Statement );while ( $DATA = array_shift( $RESULT ) ) {    // Do stuff with the data}

因此用法和语法几乎相同。主要区别在于替换函数返回结果数组,而不是结果对象。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/594715.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号