Log in

View Full Version : connect to mysql



froggy
01-05-2009, 05:57 PM
Hi there, I am new to mysql and PHP so hope I explain the problem ok. I am just teaching myself mysql and php.

I want to connect to my database using PHP. I have installed mysql on my pc (using the free mysql download). run it and setup a username of root and no password.

I have created a basic PHP page just to connect to the database:-



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>test</title>
</head>

<body>
<?php
$dbcnx = @mysql_connect('localhost', 'root', '');
if (!$dbcnx) {
echo '<p>Unable to connect to the ' .
'database server at this time.</p>';
exit();
}
?>
</body>
</html>


Password left blank as i have not set a password for the database.

I am running this php file on a server that has PHP support. However the server doesn't have MySQL on so for the reason of learning i have the mysql running on my pc hard disk.

How can i connect to the database on my pc from my php page running on a server?

Any info needed just ask...

thanx

Nile
01-05-2009, 06:04 PM
Ok, don't completely understand what you are saying. You cannot connect from a host to another host's sql host - you must connect from a host to its sql host.
If you can't get php to work on your localhost - try downloading WAMP (http://www.wampserver.com/en/).

Please rephrase your question.

froggy
01-07-2009, 05:53 PM
It was wampserver i needed to solve my problem. I couldn't do it the way i was trying to as database on different server to my php files.

Thank you for you help. Im just learning sql and php so the wamp server is perfect for me.

froggy
01-07-2009, 05:55 PM
I dont have the option to resolve a post - not sure why!