[ciapug] Question on MetaType in adodb lib
Mark Mikkelson
mikkelson_mt at msn.com
Wed Sep 21 13:32:02 CDT 2005
I solved my initial error message, and I'm sure you all caught the fact that
I left out the $rs->MoveNext() command in my original code...that was an
oversight in the email. So this is the new code that I have gotten to work
as far as returning the actual column datatype...
ADOLoadCode('mssql');
$db = ADONewConnection('mssql');
$db->debug = false;
$db->connect(dbserver,userid,password,dbname);
$db->SetFetchMode(ADODB_FETCH_ASSOC);
$sql = " select * from table where column = 'someval' ";
$rs = $db->Execute($sql);
while (!$rs->EOF) {
$count = count($rs->fields);
for ($i = 0; $i < $count; $i++) {
$fld = $rs->FetchField($rs->fields($i));
if ($fld->type == "bit") {
//work with this field
}else{
//ignore these other fields
}
}
$rs->MoveNext();
}
what I want however, is to be able to determine the datatype of the column
from a callback using array_filter, however this is what I get when I run
the following...
echo array_filter($rs->fields,"getTypes");
function getTypes($var) {
echo "<pre>\n";
var_dump($var);
echo "</pre>\n";
}
int(2)
string(15) "928 "
int(1)
int(1)
int(1)
int(1)
int(0)
int(0)
int(0)
int(0)
int(0)
int(0)
int(0)
int(0)
int(0)
NULL
NULL
NULL
NULL
NULL
NULL
string(19) "2005-09-16 12:20:53"
string(19) "2005-09-16 12:20:53"
so obviously, it is passing the value of the array at that index instead of
the field object itself...is there another way to go about this?
_____
From: ciapug-bounces at cialug.org [mailto:ciapug-bounces at cialug.org] On Behalf
Of Mark Mikkelson
Sent: Wednesday, September 21, 2005 12:24 PM
To: ciapug at cialug.org
Subject: [ciapug] Question on MetaType in adodb lib
I have a recordset that I would like to be able to filter based on the
MetaType value of the current field, so that I can display information that
is only stored in "bit" fields instead of all the other info that I pulled
into my recordset for purposes elsewhere in the code. Does anyone know of a
way to do this? Here is what I have tried so far...
ADOLoadCode('mssql');
$db = ADONewConnection('mssql');
$db->debug = false;
$db->connect(dbserver,userid,password,dbname);
$db->SetFetchMode(ADODB_FETCH_ASSOC);
$sql = " select * from table where column = 'someval' ";
$rs = $db->Execute($sql);
while (!$rs->EOF) {
foreach ($rs->fields as $k => $v) {
if ($db->MetaType($rs->fields[$k]) == "L") { //failure on this
line: Call to undefined method ADODB_mssql::MetaType()
echo $v . "<hr />\n";
}
}
}
Mark Mikkelson
MCSA Messaging, CIW Professional
Web Specialist
mikkelson_mt at msn.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://cialug.org/pipermail/ciapug/attachments/20050921/adea1961/attachment-0001.htm
More information about the ciapug
mailing list