Copy link to clipboard
Copied
Hello, My teacher has given me acess to his mysql db so I could do a project but I'm having trouble connecting to it.
here is the code that I'm using
<!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">
<?php
// we connect to example.com and port 3307
$link = mysql_connect('db****.perfora.net ', 'dbo****** ', 'n****);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
// we connect to localhost at port 3307
$link = mysql_connect('**** ', 'db******, '*****');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>
<body>
</body>
</html>
I used *'s so no one could get acess to it besides me
Copy link to clipboard
Copied
Also it gives me this when I try to load the page:
Warning: mysql_connect() [function.mysql-connect]: Unknown MySQL server host 'db****.perfora.net ' (1) in /Volumes/Storage/webserver/students/2009/web/ftp_01_10/mysql/test1.php on line 12
Could not connect: Unknown MySQL server host 'db2184.perfora.net ' (1)so when I load the page it gives me this :
Copy link to clipboard
Copied
The correct syntax for connecting to a MySQL database is
$link = mysql_connect('hostname', 'username', 'password');
If you're connecting on a nonstandard port, such as 3307 (the default is 3306), you need to add the port number to the hostname, separated by a colon like this:
$link = mysql_connect('hostname:3307', 'username', 'password');Most hosting companies do not permit remote connections to a database, so your script needs to be on the same server as the database, unless the correct permissions have been established.
Copy link to clipboard
Copied
I tried using your code but it still didn't connect I thought I would check the version of php on my teacher's server (not the one that provides him the database, his server in his classroom)

and I used this code
<?php
// This is an example opendb.php
$link = mysql_connect('db****.perfora.net', 'dbo3**26***8 ', 'w**********');
?>
Copy link to clipboard
Copied
The code that I gave you was generic code. You replace 'hostname', 'username', and 'password' with the actual values. Judging from the code you have posted here, that's what you have done. Use die to get any error message:
$link = mysql_connect('db****.perfora.net', 'dbo3**26***8 ', 'w**********')
or die(mysql_error());I suspect that you are trying a remote connection, which is being rejected by MySQL. If that's the case, you'll need to get your teacher to change the permissions to allow remote connections.
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more