View Full Version : Connecting to a mySQL DB

01-03-2006, 01:23 AM
When I try to connect to my database (myhomepageUsers) i get this error:

Warning: mysql_connect() [function.mysql-connect (http://www.php.net/function.mysql-connect)]: Unknown MySQL server host 'myhomepageUsers' (11001) in c:\program files\e-novative\WAMP\www\mySQL\index.php on line 5

with this code:
I don't understand why this happens because the database exists. Can anybody please help me?

Also, how would i retreive data from a table in a database?

Velox Letum
01-03-2006, 01:25 AM
Read: mysql_connect() (http://www.php.net/function.mysql-connect) and mysql_select_db() (http://www.php.net/function.mysql-select-db)

01-03-2006, 06:16 AM
Your connection should look something like this:

$connection = mysql_connect('localhost here','username here','password here');
if (!$connection) {
die( '<p>Access denied! Database Connection Error: ' . mysql_error() . '</p>');

Velox Letum
01-03-2006, 06:44 AM
You can simplify that a lot with a simple or.

$connection = mysql_connect('localhost','username','password') or die('Error connecting to database: ' . mysql_error());

// Also have to select the database.

01-03-2006, 08:31 PM
Yes i know, i reframed my code to something similar to that, I can connect to the server, but I cannot connect to the db, this i do not understand, do i need to export it or somthing?

01-03-2006, 08:33 PM
post your connection code (without your u/p, or other personal data)

01-03-2006, 08:39 PM
$user = "username";
$pass = "password";
$db = "homepage_users";
$link = mysql_connect ( "localhost", $user, $pass );
if ( ! $link ) {
die ( "Cound not connect ".mysql_error() );
print "<h2>Successful Connection to server</h2>";
mysql_select_db( $db, $link )
or die ( "Cound not connect to database." );
print "<h2>Successful Connection to database</h2>";
mysql_close( $link );

01-03-2006, 08:43 PM
Try this way:


$host = 'localhost';
$user = 'user';
$pass = 'password';
$db = 'db';

$m_connect = @mysql_connect($host,$user,$pass) or die ("Error while trying to connect to mysql: " . mysql_error());

$select_my_db = @mysql_select_db($db,$m_connect) or die ("Error selecting database: " . mysql_error());


01-03-2006, 08:52 PM
~ Never mind, I've got it sorted, thank you all very much for your help ~

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum