Jump to content

[SOLVED] Quick connection question


idire

Recommended Posts

New to oo php, trying to work out mysql connections in classes.

 

Here is the code:

 

<?php
class dbHandle
{
const HOST = 'localhost'; // Server
const USERNAME = 'root'; // Username
const PASSWORD = ''; // Password
const DATABASE = 'db1'; // Database Name

function connect()	// Database Connection
{
	$this->conn = mysql_connect(HOST, USERNAME, PASSWORD) or die("Database Connection Failure");
	mysql_select_db(DATABASE);
}
}

$test = new dbHandle();
$test->connect()
?>

 

I get:

 

Warning: mysql_connect() [function.mysql-connect]: Unknown MySQL server host 'HOST' (11004) in class_lib.php on line 11

 

Have I defined something wrong? I'm not sure what to declare as $ variables in classes and what not to

Link to comment
https://forums.phpfreaks.com/topic/133193-solved-quick-connection-question/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.