On Wed, Oct 8, 2008 at 3:34 PM, William Piper <[EMAIL PROTECTED]> wrote:
> William Piper wrote:
>
> Oh, I forgot to mention, "$this" only works in the class scope. If you
> are calling the methods from outside, you would need to refer it via the
> class name variable. For example:
>
> <?php
> include('mydbclass.php');
> $dbclass = new Data_Base();
> $dbclass->Connect();
> mysql_query('SELECT * FROM blah',$dbclass->handle);
> ?>
Better still would be a query method on your dbclass...
class Data_Base {
function query($sql) {
return mysql_query($sql, $this->handle);
}
}
$dbclass->query('SELECT * FROM blah');
You can do all sorts of things then, including automatically
connecting the first time you run a query, etc.