[nycphp-talk] PHP 5 Baffles Me
Derek DeVries
devrieda at gmail.com
Mon Aug 8 18:27:10 EDT 2005
You're calling a method of Database that doesn't exist, hence the
error "Call to undefined method. You define the class Database, but it
has no Open(), Query(), FetchArray() or Close() methods defined. If
you want it to inherit methods from some base class, you're going to
need to define your class doing something like:
class Database extends BaseClass {
}
what is this using() function at the top? Is that a user defined
function that does a require on a file in the path?
ps... I hope that's not your actual user/pass pasted in the code... if
so I would change it now that it has been shared with a bunch of
strangers.
Derek
On 8/8/05, Joseph Crawford <codebowl at gmail.com> wrote:
> Hey Guys,
>
> i am working on a database class however i am not getting the expected
> results.
>
> <?php
> using("System.Database.Drivers");
> class Database {
>
> public function __construct($dsn =
> 'mysql://csaf:bose343@localhost/csaf', $persistant = false)
> {
> $d = explode(':', $dsn);
> $driver = ucfirst(strtolower($d[0]));
> if(isset($driver)) {
> if(isset($dsn)) return new $driver($dsn, $persistant);
> else throw new DatabaseEx('Invalid DSN');
> }
> else throw new DatabaseEx('Invalid Driver!');
> }
> }
>
> $dsn = "mysql://user:pass@localhost/csaf";
> $db = new Database($dsn);
> $db->Open();
> $res = $db->Query("SELECT username FROM admins WHERE id=1");
> $data = $db->FetchArray($res);
> $db->Close();
> print_r($data);
> ?>
>
> i get the follwing error with that code.
>
> Fatal error: Call to undefined method Database::Open() in
> E:\htdocs\csaf1\global.php on line 156
>
> if i do
> if($db instanceof Mysql) echo "YAY";
> it never echo's but if i change Mysql to Database it will echo.
> Any help / explanation would be appreciated.
>
> --
> Joseph Crawford Jr.
> Codebowl Solutions, Inc.
> 1-802-671-2021
> codebowl at gmail.com
> _______________________________________________
> New York PHP Talk Mailing List
> AMP Technology
> Supporting Apache, MySQL and PHP
> http://lists.nyphp.org/mailman/listinfo/talk
> http://www.nyphp.org
>
>
More information about the talk
mailing list