Hi,
Currently I'm programming a database class which makes a little bit use of PHP's PDO class, but I'd like to add some simple features for making programming a certain application a bit easier.
Now In the following piece of pseudo code you can see where I'm going. The only problem in this example is that the $result variable is an object, which cannot be used for comparisation of some stuff I'm doing further on in the script:
<?php
class Database
{
public function FetchRow ( $query )
{
// .. do some stuff, and make a $result variable
return DatabaseStatement ( $result );
}
}
class DatabaseStatement
{
private $result;
public function __construct ( $query )
{
// .. save result in property etc.
}
public function __get ( $column )
{
// .. check result item
return $this -> result [ $column ];
}
}
$db = new Database;
$result = $db -> Query ( 'SELECT * FROM users WHERE id = 1;' );
if ( $result != null ) // Here $result should be an array OR null in case no rows are returned
{
echo $result -> username; // Here $result should call the __get method
echo '<pre>' , print_r ( $result ) , '</pre>'; // Here $result should be the array, cause it wasn't null just yet
}
As you can see the $result variable should not be an object when I'm doing a comparisation, I know it can be made to a string using __toString. But I'd like it to be some other type, mostly an array or null.
Now my question is simple: how do I get something like that working if it's possible (should be possible I think with too much hassle)?
I already did some searches on Google, but no result, and proberbly I'm not using the correct keywords, I don't really know what to search for.
So can somebody point me in the right direction, or possibly give a piece of code that should work or I can change to fit in my current class?
Thanks so far..!
Stefan