Help with making a class or connect function
| From: | frank mancuso | Date: | Tue, 03 Sep 2002 00:36:59 +0000 |
| Subject: | Help with making a class or connect function | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-21543@lists.php.net to get a copy of this message | ||
Hi I made this.
<?
//config.php
$sqlhost = "localhost";
$sqluser = "root";
$sqlpasswd = "password";
$sqldatabase = "project";
?>
<?
//sqlclass.php
require('config.php');
class Connect {
var $link;
function Connect() {
$this->link = mysql_connect($sqlhost,$sqluser,$sqlpasswd);
$select = mysql_select_db($sqldatabase,$this->link);
}
}
?>
<?
//index.php
require('config.php');
require('sql.php');
$class = new Connect;
$query = "SELECT * from houses WHERE city='toronto'";
$result = mysql_query($query,$class->link);
$row = mysql_fetch_array($result);
echo "$row[title]"
."$row[firstname]";
?>
What I'm trying to do is make a function or class that I can call up when
ever I want to connect to mysql.
If anyone can explain if I've done something wrong or if I'm not calling the
function up.