从execute()转换数组

时间:2015-05-10 15:28:50

标签: php

<?php

function hwthau_verify( $redr_userid, $loss_check )


    $stmt = $dbh->prepare( $query );
    $stmt->execute( );
    $result = $stmt->fetchall( );
    $numk = count( $result['CERT_ID'] );
    $ary1 = array( );
    $value1 = each( $result );
    $value1 = $value1[1];
    $key = each( $result );
    $key = $key[0];

    while ( each( $result ) )
    {
        do
            $value = each( $value1 );
            $value = $value[1];
            $key1 = each( $value1 );
            $key1 = $key1[0];
            if ( each( $value1 ) )
            {
                $ary1[$key] = $value;
            }
        while(1)
    }

    $redr_type_code_first = $ary1['REDR_TYPE_CODE'];
    $redr_type_name = $ary1['REDR_TYPE_NAME'];
    $redr_flag = $ary1['REDR_FLAG'];
    $cert_flag = $ary1['CERT_FLAG'];
    $chk_validity_period = $ary1['CHK_VALIDITY_PERIOD'];
    $bgn_date = $ary1['BGN_DATE'];
    $end_date = $ary1['END_DATE'];
    $LocalDay = $ary1["TO_CHAR(SYSDATE,'YYYY-MM-DD')"];
    $password = $ary1['PASSWORD'];
    $str1 = $ary1['CERT_ID'];
    $PWD_CHECK_FLAG = $ary1['PWD_CHECK_FLAG'];

我想创建一个用于身份验证的API。但我有一个问题。如果AS $ result = $ stmt-&gt; fetchall();转换ary1 = array();看起来我的代码不起作用。我不知道他为什么写那个

  do
            $value = each( $value1 );
            $value = $value[1];
            $key1 = each( $value1 );
            $key1 = $key1[0];
            if ( each( $value1 ) )
            {
                $ary1[$key] = $value;
            }
        while(1)

它看起来像一个闭环。

1 个答案:

答案 0 :(得分:1)

为什么不使用foreach代替while

你可以像这样使用它:

<?php
foreach($result as $row){
  $redr_type_code_first = $row['REDR_TYPE_CODE'];
  $redr_type_name = $row['REDR_TYPE_NAME'];
  $redr_flag = $row['REDR_FLAG'];
  $cert_flag = $row['CERT_FLAG'];
  $chk_validity_period = $row['CHK_VALIDITY_PERIOD'];
  $bgn_date = $row['BGN_DATE'];
  $end_date = $row['END_DATE'];
  $LocalDay = $row["TO_CHAR(SYSDATE,'YYYY-MM-DD')"];
  $password = $row['PASSWORD'];
  $str1 = $row['CERT_ID'];
  $PWD_CHECK_FLAG = $row['PWD_CHECK_FLAG'];
}
?>