how do i connect to a remote database

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Kingo
Forum Contributor
Posts: 146
Joined: Thu Jun 03, 2004 9:38 am

how do i connect to a remote database

Post by Kingo »

Hello,
As i did not have the database, i'm using an online free database.
These people gave me the following info

http://www.freesql.org
port 3306
database name : xxx
user: yyy
password: zzz

How do i connect to the database?
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Code: Select all

$db = mysql_connect("www.freesql.org:3306", "yyy", "zzz") or die("Cannot connect to database.");
mysql_select_db("xxx", $db) or die("Couldn't select database.");
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Firstly... make sure your free Hosting service doesn't have the mysql functions disabled. I know T35.com have them disabled for the free service.

If they're not then you just use

Code: Select all

$server = "www.freesql.org";
$user = "xxxxx";
$pass = "xxxxx";
$database = "xx";
$port = "3306"; //The default port so you don't really need to specifiy it

$connect = mysql_connect($server . ':' . $port, $user, $pass); //looks like http://www.freesql.org:3306,xxxxx,xxxxx
mysql_select_db($database);

mysql_close($connect); //at the end of using the db

?>
Voila. But check the functions are enabled first! ;-)
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

I notice a lot of british people are still up at this time! Everyone busy trying to cram lots of work in before xmas or something :-D ?
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

thread hijack - xmas

Post by timvw »

bleh :P

beautiful women cost a lot of money, so i gotta make lots of money ;)) and make some programs in http://euler.sf.net as a replacement for my math exam in january...

ah well, you can http://home.mysth.be/~timvw/demo (user: timvw pass: password) (packages -> select a package and choose maintain files -> choose create). the idea is that users can create packages, and those packages can contain files they have on their server.... we want to make it as easy as possible, therefore they only have to install 1 file on their server... and pass us the url of where that file is located...
Post Reply