[RESOLVED] Undefined Variable
Sorry to ask this n00b question.:(
It's just my 2nd day in php.
I have this class database connection:
PHP Code:
<?php
class DBConnection{
private $link;
public function connect(){
include 'connstring.php';
$link = mysql_connect($host,$user,$pw);
if(!$link)
{
die('Could not connect'.mysql_error());
}
}
public function close()
{
mysql_close($link);
}
}
?>
But when I call connect and close function the errors come out.
Quote:
Notice: Undefined variable: link in C:\Program Files\Apache Group\Apache2\htdocs\connection.php on line 16
Warning: mysql_close(): supplied argument is not a valid MySQL-Link resource in C:\Program Files\Apache Group\Apache2\htdocs\connection.php on line 16
why? :confused:
edit: using do the trick.
Re: [RESOLVED] Undefined Variable
Have you seen the article in my sig about PHP 5 OOP? I have made a database wrapper example there. You may find it useful, even if your script isn't in PHP 5.