1

以下は、テーブルから複数のデータを取得するために使用している関数のコードですが、bind_result($ array [0]、...、..)を使用して、フィールドの数に応じて自動的に生成されます。クエリで選択します。

例えば..

$query=select a,b,c,d,e from table;//selecting 5 fields
......
$stmt->execute();$stmt->bind_result($retrieve[0],$retrieve[1],$retrieve[2],$retrieve[3],$retrieve[4]);

(5つの値のbind_resultは自動的に生成されます)ヘルプは高く評価されます...ありがとう

$query="SELECT comment, userid,UNIX_TIMESTAMP(dtime)
                FROM comment_updates
                WHERE updateid=46546
                ORDER BY dtime DESC
                LIMIT 10 ";
        if($stmt = $this->conn->prepare($query)) {
            $stmt->execute();
            $stmt->bind_result($comments[0],$comments[1],$comments[2]);
            $i=0;
            while($stmt->fetch()){
            $i++;
            $name='t'.$i;
            $$name = array($comments[0],$comments[1],$comments[2]);
            }
            return array($i,$t1,$t2,$t3,$t4,$t5,$t6,$t7,$t8,$t9,$t10);
            $stmt->close();
        }
4

1 に答える 1

1

これで始められるはずです:

http://php.net/manual/en/mysqli-stmt.result-metadata.php

これにより、を介して結果セットのフィールド数が取得されますmysqli_num_fields()

$retrieveこれは、配列のサイズである必要があります。

引数としてbind_result配列をとらないので、call_user_func_arrayこれを達成するために使用する必要があります:

call_user_func_array(array($stmt, 'bind_result'), $retrieve_references);

$retrieve_references内の要素への参照の配列である必要があります$retrieve$retrieveでそれ自体を使用call_user_func_arrayすると、エラーが発生します。

于 2009-07-06T20:41:08.440 に答える