MYSQL connect through PHP
-
Hi, I have an email through my web hosting service which has told me my database details. they go MySQL Hostname: 99.99.999.999 MySQL Username: xxx xxx MySQL Passwor: aaaaahh MySQL Server: MySQL 1 I was able to connect to a differnet database which did not have mysql server on it by using the following code
$hostname = "99.99.999.999"; $password = "aaaaahh"; $username = "xxx xxx";
Now i thought that this was simply going to be adding a $server variable on underneath so the complete code would look like this$hostname = "99.99.999.999"; $password = "aaaaahh"; $username = "xxx xxx"; $server = "MySQL 1"; $connection = mysql_pconnect($hostname, $server, $username, $password); if (!$connection) { die('Could not connect: ' . mysql_error()); } echo 'Connected successfully'; mysql_close($connection) ?>
However this doesn't seem to do anything? Any help would be great Many Thanks Dan -
Hi, I have an email through my web hosting service which has told me my database details. they go MySQL Hostname: 99.99.999.999 MySQL Username: xxx xxx MySQL Passwor: aaaaahh MySQL Server: MySQL 1 I was able to connect to a differnet database which did not have mysql server on it by using the following code
$hostname = "99.99.999.999"; $password = "aaaaahh"; $username = "xxx xxx";
Now i thought that this was simply going to be adding a $server variable on underneath so the complete code would look like this$hostname = "99.99.999.999"; $password = "aaaaahh"; $username = "xxx xxx"; $server = "MySQL 1"; $connection = mysql_pconnect($hostname, $server, $username, $password); if (!$connection) { die('Could not connect: ' . mysql_error()); } echo 'Connected successfully'; mysql_close($connection) ?>
However this doesn't seem to do anything? Any help would be great Many Thanks DanServer and hostname usually mean the same thing - the address of the server. In any case, you have the arguments to mysql_pconnect[^] wrong, it should be:
$connection = mysql_pconnect($hostname, $username, $password);
This is assuming the server name is in the
$hostname
variable. I suspect$server
is actually the database name, so you should select this after connection using mysql_select_db[^].if(!mysql_select_db($server, $connection)) { ...
-
Hi, I have an email through my web hosting service which has told me my database details. they go MySQL Hostname: 99.99.999.999 MySQL Username: xxx xxx MySQL Passwor: aaaaahh MySQL Server: MySQL 1 I was able to connect to a differnet database which did not have mysql server on it by using the following code
$hostname = "99.99.999.999"; $password = "aaaaahh"; $username = "xxx xxx";
Now i thought that this was simply going to be adding a $server variable on underneath so the complete code would look like this$hostname = "99.99.999.999"; $password = "aaaaahh"; $username = "xxx xxx"; $server = "MySQL 1"; $connection = mysql_pconnect($hostname, $server, $username, $password); if (!$connection) { die('Could not connect: ' . mysql_error()); } echo 'Connected successfully'; mysql_close($connection) ?>
However this doesn't seem to do anything? Any help would be great Many Thanks DanHi, You are doing it wrong. The correct syntax of mysql_pconnect is:
$connection = mysql_pconnect($server, $username, $password, $client_flags);
So, if you have the hostname, you must use it instead of using ServerName. So, all you have to do is use this piece of code:
$hostname = "99.99.999.999";
$password = "aaaaahh";
$username = "xxx xxx";
$server = "MySQL 1";$connection = mysql_pconnect($hostname, $username, $password);
if (!$connection)
{
die('Could not connect: ' . mysql_error());
}echo 'Connected successfully';
mysql_close($connection);See, I have not used $server anywhere. Not needed. Give it a try. Enjoy.
Procrastination and Improvisation are my two swords to fight life. My Portfolio Website
-
Hi, I have an email through my web hosting service which has told me my database details. they go MySQL Hostname: 99.99.999.999 MySQL Username: xxx xxx MySQL Passwor: aaaaahh MySQL Server: MySQL 1 I was able to connect to a differnet database which did not have mysql server on it by using the following code
$hostname = "99.99.999.999"; $password = "aaaaahh"; $username = "xxx xxx";
Now i thought that this was simply going to be adding a $server variable on underneath so the complete code would look like this$hostname = "99.99.999.999"; $password = "aaaaahh"; $username = "xxx xxx"; $server = "MySQL 1"; $connection = mysql_pconnect($hostname, $server, $username, $password); if (!$connection) { die('Could not connect: ' . mysql_error()); } echo 'Connected successfully'; mysql_close($connection) ?>
However this doesn't seem to do anything? Any help would be great Many Thanks DanServer isnt a accepted value in the connection string.