PEAR - mssql.php
| From: | David Clark | Date: | Mon, 22 Jul 2002 16:07:49 +0000 |
| Subject: | PEAR - mssql.php | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-7859@lists.php.net to get a copy of this message | ||
My company uses PHP 4.2.1 running on Apache 1.3.22 (on Linux) with FreeTDS
0.53 to connect to a MS SQLServer 2000 database. I've noticed a few
problems with the PEAR DB implementation for mssql, primarily that the
"tableInfo" function does not work at all, given the handle to a query
result. I don't believe it works when you pass it the name of a table
either, but even if it did, the way it does so seems somewhat inefficient
because of the "SELECT * FROM ..." query that results.
I've pasted below the modified code that I've used to work around this
problem, though it's not set up to support the "mode" parameter to the
function. Also, possibly due to FreeTDS, it's impossible to obtain the base
table name for each column/field in a query (the result for that field is
always empty). As with the original PEAR code for this function, mine does
not fill in the "flags" field in the return array, but, given a table name
it is possible to find the key fields for that table easily enough (using
the sp_pkeys system stored procedure in SQLServer) - has anyone talked of
trying to work this into the routine to populate the "flags" field (or is
the purpose of the "flags" more for NULL-ability, etc. than for key
designations)?
Any help/input that could be offered would be great, even if it ends up
simply being that FreeTDS is the problem...
-David Clark
dclark@rastardm.com
>>>
function tableInfo($result, $mode = null)
{
$count = 0;
$id = 0;
$res = array();
/*
* $result[]:
* [0]["table"] table name
* [0]["name"] field name
* [0]["type"] field type
* [0]["len"] field length
* [0]["flags"] field flags
*
*/
// if $result is a string, then we want information about a
// table without a resultset
if (is_string($result)) {
$id = @mssql_query("SELECT TOP 0 * FROM $result",
$this->connection);
if (empty($id)) {
return $this->mssqlRaiseError();
}
} else { // else we want information about a resultset
$id = $result;
if (empty($id)) {
return $this->mssqlRaiseError();
}
}
$i = 0;
while ($curField = mssql_fetch_field($id)) {
$res[$i]['table'] = (is_string($result)) ? $result : '';
$res[$i]['name'] = $curField->name;
$res[$i]['type'] = $curField->type;
$res[$i]['len'] = $curField->max_length;
$res[$i]['flags'] = '';
$i++;
}
// free the result only if we were called on a table
if (is_string($result)) {
@mssql_free_result($id);
}
return $res;
}