PHP Class Question
Posted: Mon Mar 12, 2007 5:52 pm
I'm using a class I found for mysql functions and such. The way they implement it, you have to connect each time you want to use a function in the class. I want a way to make it so I won't have to call a connection each time I create an SQL statement. The example they use is:
I want to put $db->connect(localhost,user,pass,db); Into a file such as config.php and use something like:
This way I only have to include one file such as config.php whenever I want to call an sql statement. How would I do this? If I try just using $this->connect in a config.php file I get an error:
I've tried just putting this into my config.php file but to no avail I receive another error:
I receive:
Code: Select all
require_once('./mysql.php');
$db = new MySQL;
$db->connect(
localhost,
test_user,
test_pass,
test_db
);
$result = $db->query("SELECT * FROM test_table");
echo $db->num_rows($result);Code: Select all
$this->connect($host, $user, $pass, $db);Code: Select all
[B]Fatal error:[/B] Using $this when not in object context in I:\Apache\htdocs\test.php on line 5Code: Select all
require_once('./mysql.php');
$db = new MySQL;
$db->connect(
localhost,
test_user,
test_pass,
test_db
);Code: Select all
Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in I:\Apache\htdocs\class\mysql.class.php on line 91
Error: 0: