Re: some MDB2 questions
| From: | Andreas Korthaus | Date: | Thu, 10 Feb 2005 12:26:13 +0000 |
| Subject: | Re: some MDB2 questions | ||
| References: | 1 2 | Groups: | php.pear.dev |
| Request: | Send a blank email to pear-dev+get-36118@lists.php.net to get a copy of this message | ||
Lukas Smith wrote:
What about the API - is it in sync with PDO now? I think PDO API is finished / beta since yesterday, right?[affectedRows()]yes, this is inline with ext/pdo is doing it.
Ah, it is not implemented as "abstract" methode, only inside every driver, I see.But how can I use something like numRows() as in DB_Result? Should I request the $rownum property?no, same as in PEAR::DB $result->numRows();
keep in mind that numRows() is a senseless feature though. The cost of determening the number of rows is usually quite close to fetching the entire result set.But it's nice to check if there is for example only exact one line or no line returned from database.
Ah, would be nice I think.Does MDB2 support a syntax similar to ADOdb'sIt will in the future provide a similar syntax in that you can bind result columns to variables. So all you have to do is move the internal pointer forward.while (!$rs->EOF) { print_r($rs->fields); $rs->MoveNext(); }
But this is only PHP5 compatible. Does it make sense to stay compatible to older PHP-Versions for MDB2? If it becomes stable I think a lot of hosters offer PHP5... (most of the large hosters in germany offer php5 today!). I think most people will use it only for new projects - and these will used php5!What is necessary to use the iterator from Iterator.php (foreach...)?I still need to work out some issues when making internal fetch calls, but basically you can use: $mdb2->setOption('result_wrap_class', 'MDB2_Iterator'); havent tried this in a while though :-)
[autoExecute() methode for ADOdb]
Err, what exactly do you want changed? Is this a tweaked version of what is there, or does this provide more/less features?compared to http://cvs.php.net/co.php/pear/MDB2/MDB2/Extended.php?r=1.17#142 I think it is somewhat more efficent, there is no new functionality, I basically replaced the php-loops with c-functions. The function I posted before could replace buildManipSQL() from MDB2. There is my version of AutoExecute() I hoped to get into ADOdb, it only calls prepare() and execute(). // complete AutoExecute() with no extra methodes needed // - does not perform extra query as GetInsertSQL() and GetUpdateSQL() // - does not use extra mothodes to build and prepare the sql-query // - uses implode() and str_repeat() instead of .= and foreach as PEAR::DB does function AutoExecute($table, $table_fields, $mode = 'INSERT', $where = false) {
if (count($table_fields) == 0) {
ADOConnection::outp('AutoExecute: insufficient data supplied');
return false;
}
switch ((string) $mode) {
case 'INSERT':
case '1':
$cols = implode(',', array_keys($table_fields));
$values = '?'.str_repeat(',?', count($table_fields)-1);
$sql = 'INSERT INTO '.$table.' ('.$cols.') VALUES ('.$values.')';
break;
case 'UPDATE':
case '2':
$set = implode('= ?,', array_keys($table_fields)).'= ?';
$sql = 'UPDATE '.$table.' SET '.$set;
if ($where !== false) $sql .= ' WHERE '.$where;
else {
ADOConnection::outp('AutoExecute: Illegal mode=UPDATE with empty WHERE clause');
return false;
}
break;
default:
ADOConnection::outp("AutoExecute: Unknown mode=$mode");
return false;
}
$stmt = $this->Prepare($sql);
if ($stmt) return $this->Execute($stmt, array_values($table_fields));
return false;
}
I'm looking forward to it! AndreasWill there be a beta3 release in near future?Basically I am just trying to get the fbsql and mssql drivers working. Even if I dont I will make a new release sometime this month.