4.07 RC2 problem/bug with ADO databases
| From: | Pete Dishman | Date: | Wed, 12 Sep 2001 15:03:48 +0000 |
| Subject: | 4.07 RC2 problem/bug with ADO databases | ||
| Groups: | php.qa | ||
| Request: | Send a blank email to php-qa+get-3594@lists.php.net to get a copy of this message | ||
Hi,
not sure if this is the right place to report this but I wasn't sure if it
should be reported as a proper bug seeing as it's only with the release
candidate.
I've been using the ADODB wrapper to retrieve data from an Access database
but since trying out the latest release candidate I've found a strange
problem with checkboxes (from access) and testing against boolean variables.
In the sample code below I pull out a couple of records from a table where
one of the fields is a checkbox (this is all done using the ADO com
objects). The variable created by this representing the checkbox is
reported (by var_dump) as being a boolean, as expected. The problem comes
when checking the value of this boolean.
If you use
if ($var == true)
echo "it's true";
it never works even when var_dump reports that the boolean is true.
If however you use
if ($var)
echo "it's true";
it works as it's expected to.
Everything works fine under PHP 4.06 so I assume this is a PHP problem,
either with the basics or more likely with the COM module.
Sample Code:
Note this uses an access database with a system DSN ('testDB')
The database contains one table ('Table1') with three fields the final field
is a checkbox and the fields are called 'ID', 'testtext' and
'checkbox'
The code does two checks on the returned checkbox, both of which you would
expect to return the same result. Under 4.06 they do and 407RC2 they don't
<?php
// Create the com object and connect to the database
$db = new COM('ADODB.Connection');
$db->Provider = 'MSDASQL';
$db->Open('testDB');
$szSQL = "SELECT * FROM Table1";
// Get the record set object by executing the SQL
$objResult = $db->Execute($szSQL, false);
// build up a 2d array of the results
for ($nCount=0; $nCount < 4; $nCount++)
{
$Fields = $objResult->Fields("ID");
$aData[$nCount][0] = $Fields->Value();
$Fields = $objResult->Fields("TestText");
$aData[$nCount][1] = $Fields->Value();
$Fields = $objResult->Fields("CheckBox");
$aData[$nCount][2] = $Fields->Value();
$objResult->MoveNext();
}
// Loop through the error, dumping data on each of the set variables
for ($nCount =0; $nCount < 4; $nCount++)
{
echo "<B>Record $nCount</B><BR>";
var_dump($aData[$nCount][0]);
echo "<BR>";
var_dump($aData[$nCount][1]);
echo "<BR>";
var_dump($aData[$nCount][2]);
echo "<BR>";
if ($aData[$nCount][2] == true) // Check the checkbox against
true
echo "var is true<BR>";
else
echo "var is false<BR>";
if ($aData[$nCount][2]) // check it directly
echo "var is true<BR>";
else
echo "var is false<BR>";
echo "--------------------------------<BR>";
}
?>
//////
Output to the browser.
Record 0
int(1)
string(4) "test"
bool(true)
var is false
var is true
--------------------------------
Record 1
int(2)
string(2) "if"
bool(false)
var is false
var is false
--------------------------------
Record 2
int(3)
string(4) "this"
bool(false)
var is false
var is false
--------------------------------
Record 3
int(4)
string(5) "works"
bool(true)
var is false
var is true
--------------------------------
Apart from this I've found no other problems with RC2, running under NT 4
server with apache 1.3.20 and ADODB connecting to Access database(s)