Wednesday, 15 July 2015

php - Defining a mySql result as a variable for a while loop -



php - Defining a mySql result as a variable for a while loop -

i wondering if possible. know hardly practical...i did though, run case might come in handy.

take example, straight forward.

while( $row = $qry->fetch(pdo::fetch_assoc) ){}

now, can done?

$newvar = '$row = $qry->fetch(pdo::fetch_assoc)'; while($newvar){}

i have tried many ways no avail.

my while loops print out lot of info , depending on type of query/connection (mysql, mysqli, or pdo) depend on statement goes while loop.

this fallback thought if prepared statements not supported.

if function fetch row different, may able utilize closures depending on php version using. utilize closures, want define function knows how fetch row, can pass while loop. example, here closures pdo , mysql:

$pdo_fetch = function() utilize ($qry) { homecoming $qry->fetch(pdo::fetch_assoc); } $mysql_fetch = function() utilize ($result) { homecoming mysql_fetch_assoc($result); }

these closures can come anywhere, passed while loop:

if($pdo) { $fetch = $pdo_fetch; } else { $fetch = $mysql_fetch; } while($row = $fetch()) { }

php mysql row

No comments:

Post a Comment