1

異なるバインディング結果でステートメントを2回使用することは可能ですか?例:最初のスクリプトには2番目のスクリプトが含まれています。firstscript.phpで、プリペアドステートメントはselectを実行し、最初の出力の変数によって結果をバインドします。出力は、たとえば結果の量である可能性があります。スクリプトにはsecondscript.phpが含まれています。

// firstscript.php
$sql ="SELECT field1,field2,field3,field4 FROM table WHERE table.field1=? AND table.field2=?";
$stmt->bind_params("si",$para1,$para2);
$stmt = $con->prepare($sql);
$stmt->bind_result($field1,$field2,$field3,$field4);
$stmt->execute();
$stmt->num_rows();
while($stmt->fetch())
    {
    //output
    }
$stmt->close();
include(secondscript.php);

secondscript.phpは、ステートメントオブジェクトを再利用して、結果を制限するとともに、新しい選択を行います。出力の場合、ステートメントには出力に対して他のバインディング結果が必要です。

// secondscript.php
$limit = " LIMIT 0,5";
//use the same statement from first script in conjunction with $limit
$stmt->prepare($sql.$limit);
$stmt->execute();
/*
// case 1
//without binding results 
while($stmt->fetch())
    {
    //no output
    }

// case 2
//with binding results - like in the first script
$stmt->bind_result($field1,$field2,$field3,$field4);
while($stmt->fetch())
    {
    //output
    }

// case 3
//same statement with *different* bindings
*/
$stmt->bind_result($field3,$field4);
while($stmt->fetch()
    {
    //output - failure; binding error
    //Warning: mysqli_stmt::bind_result(): Number of bind variables doesn't match number of fields in prepared statement
    }
$stmt->close();

再利用されたステートメントに新しいバインディング結果を最終出力に割り当てるにはどうすればよいですか?

すべてに感謝します

4

0 に答える 0