Problem with my db class
Posted: Sat Apr 10, 2004 10:10 pm
Just whipped this up, and I'm not a good OOP programmer (as you'll see in a second), but I can't even figure out why this doesn't work.. it's pathetic..
Page that calls it:
Errors:
Code: Select all
<?php //dbclass.php
Class DB {
var $dbHost = "localhost";
var $dbUser = "d3ad1ysp0rk";
var $dbPass = "squall";
var $dbName = "testdb";
var $link;
function newdb(){
$this->conn();
$this->selectdb();
}
function conn(){
$this->$link = mysql_connect($host,$dbuser,$dbpass) or die("Could not connect: " . mysql_error());
}
function selectdb(){
//debugging stuff
/*echo $dbHost;
echo $dbUser;
echo $dbPass;
echo $dbName;
echo $link;*/
mysql_select_db($dbName, $link) or die("Could not use table: " . mysql_error());
}
function endconn(){
mysql_close($link);
}
}
?>Code: Select all
<?php //testsql.php
include("dbclass.php");
if(count($_POST) > 2){
$mydb = new DB();
$mydb->newdb();
extract($_POST, EXTR_SKIP);
$sql = "INSERT INTO newtable(username,password,rank) VALUES('$username','$password','$rank')";
mysql_query($sql) or die("Error: " .mysql_error());
$mydb->endconn();
}
else {
echo "You must enter all values!!";
}
?>Thanks to anyone who can spot my mistake.Warning: mysql_select_db(): supplied argument is not a valid MySQL-Link resource in C:\Documents and Settings\Administrator\Desktop\Server\dbclass.php on line 23
Could not use table: