Hallo criminalspoints.
Ik heb sinds kort mijn website online gezet, en ik heb daarbij een database class gemaakt, die ik op een rustige ochtend zou installeren.
Nu blijkt dit moeilijker als gedacht.
Verbind code:
PHP
// Connect to MySQL
$link = Connection::NewConnection( $sql_config['hostname'], $sql_config['database'], $sql_config['username'], $sql_config['password'] );
if(!$link)
{
$message = '' . mysql_error() . '<br><br>Please inform a system administrator!';
echo <<<ENDHTML
<body bgcolor="#000000">
<center><table cellspacing='0' width='700' height='1%' style='border: 1px solid #444444; margin-bottom: 4px' cellpadding='2' >
<tr>
<td height='35' width='700' background='' bgcolor='#333333' style='border-bottom: 1px solid #444444; text-align: left; padding-left:25px; vertical-align: middle;'>
<b><font color='#999999'>A MySQL has error occured!</b>
</td>
<TR>
<td bgcolor='#222222' width='700' style='border-bottom:1px solid #444444;' height='25'>
<font color='#999999'>The website has failed to connect to the mysql server!<BR>
Error: $message </font>
</td>
</TR>
</table></center>
ENDHTML;
exit();
}
Toon Meer
Database Class:
PHP
class Connection
{
var $db_connection = null; // Database connection string
var $db_server = null; // Database server
var $db_database = null; // The database being connected to
var $db_username = null; // The database username
var $db_password = null; // The database password
var $CONNECTED = false; // Determines if connection is established
/** NewConnection Method
* This method establishes a new connection to the database. */
public function NewConnection($server, $database, $username, $password)
{
// Assign variables
global $db_connection, $db_server, $db_database, $db_username, $db_password;
$db_server = $server;
$db_database = $database;
$db_username = $username;
$db_password = $password;
// Attempt connection
try
{
// Create connection to MYSQL database
// Fourth true parameter will allow for multiple connections to be made
$db_connection = mysql_connect ($server, $username, $password, true);
mysql_select_db ($database);
if (!$db_connection)
{
throw new Exception('MySQL Connection Database Error: ' . mysql_error());
}
else
{
$CONNECTED = true;
}
}
catch (Exception $e)
{
echo $e->getMessage();
}
}
}
Toon Meer
let op, dit is slechts een deel van de database class.
ik hoop dat het op te lossen is.
Mvg, AeroXbird
EDIT: het is opgelost :slotje: