Hi group.
I have just implemented an idea in PHP that I first saw in the OpenACS web
framework.
Basically the idea is to use dynamic evaluation (eval) to introduce the
result of a database call as variables in the calling code.
So the following code:
db_one_row ("SELECT name, number FROM people LIMIT 1");
Introduces the variables name and number (from the SQL statement). Meaning
that I afterwards can write:
echo $name;
echo $number;
Instead of writing something like:
$rows = mysql_query("SELECT name, number FROM people LIMIT 1");
$row = mysql_fetch_array($rows);
echo $row[0];
echo $row[1];
Likewise I can read multiple rows by having the next method of an iterator
introducing variables in caller's scope:
$i = db_multi_row("SELECT email, name FROM email_addresses");
while ($i.next()) echo "$name : $email";
What do you think of this approach to database access? Is it good or is it
bad?
My implementation is here:
http://vredungmand.dk/programming/ez...ess/index.html
-- Christian