Here's what I'm trying to do:
Code: Select all
<?php
include 'databaser.php';
$d = new databaser;
$d->connect("localhost", "chalks_tester", "*******");
if($d->create("user", "name varchar(30), pass varchar(100)"))
echo "yay";
else
echo mysql_error();
?>Code: Select all
<?php
class databaser {
private $db;
function connect($host="localhost", $user="username", $pass="pass")
{
$this->db = mysql_connect($host, $user, $pass);
mysql_select_db($this->db);
}
function create($table, $data)
{
$table = mysql_real_escape_string($table);
$data = mysql_real_escape_string($data);
$sql = "CREATE TABLE IF NOT EXISTS $table (id int NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), $data)";
if($result = mysql_query($sql))
return true;
return false;
}
?>if I try to just cut out the class and do it this way:
Code: Select all
<?php
$db = mysql_connect("localhost", "chalks_tester", "tester") or die(mysql_error());
mysql_select_db($db) or die(mysql_error());
?>Which doesn't make sense because I KNOW that's the right username/password.
I know for a fact that I have the right username and password (I checked, rechecked, and triple checked).
I'm pretty sure I'm using the class function correctly.
Why in the world isn't this working?
EDIT: haha, I'm a moron.