Return to Help Center

Welcome to the Bravenet Help Forums. Here you can chat and meet other Bravenet Members. Please do not post advertisements.

Forum: Coding Discussions
Start a New Topic 
  
Author
Comment
PHP and MYSQL

Hello. I'm trying to use php and MySQL to create a contact manager. I just need to know how to connect to my database I created on bravehost using php. Here is the function I am using in php to try and connect but, it's failing to connect. I'm new to this so I'm pretty sure I'm just using the wrong commands. Any help would be greatly appreciated. Here is the php code I'm using to access database.

private static function _getConnection() {
static $hDB;

if(isset($hDB)) {
return $hDB;
}

$hDB = pg_connect("host=servername port=5432 " . "dbname=test_123456 user=testuser password=mypassword")

or die("Failure connecting to the database!");

return $hDB;

}

Email  
Re: PHP and MYSQL

Alright the great guys at bravenet have helped me resolve this very quickly. I felt obliged to post the fix so anyone else who's having same issue can resolve it.

private static function _getConnection() {
static $hDB;
$server="server.bravehost.com";
$username="username";
$password="databasepassword";

if(isset($hDB)) {
return $hDB;
}

$hDB = mysql_pconnect($server,$username,$password);

@mysql_select_db($dbname)
or die("Failure connecting to the database!");

return $hDB;

}

Hope this helps

Email