Couldn't connect to server
Moderator: General Moderators
-
phpBrandNew
- Forum Commoner
- Posts: 36
- Joined: Thu Sep 02, 2010 12:51 am
Couldn't connect to server
The following is my code:
<?php
$users="root";
$host="localhost";
$password="";
$database="Animal";
$connection=mysql_connect($host,$users,$password)
or die("Couldn't connect to server");
$db=mysql_select_db($database,$connection)
or die("Couldn't connect to server");
?>
The result is "Couldn't connect to server".
What are the possible reasons that cause "Couldn't connect to server" ?
<?php
$users="root";
$host="localhost";
$password="";
$database="Animal";
$connection=mysql_connect($host,$users,$password)
or die("Couldn't connect to server");
$db=mysql_select_db($database,$connection)
or die("Couldn't connect to server");
?>
The result is "Couldn't connect to server".
What are the possible reasons that cause "Couldn't connect to server" ?
Re: Couldn't connect to server
Use different error messages at different error points. It is difficult to isolate the problem if all the error messages are identical.
Also, mysql_error() and mysql_errno() will return more useful information than a generic "Couldn't connect to server" message.
Also, mysql_error() and mysql_errno() will return more useful information than a generic "Couldn't connect to server" message.
-
phpBrandNew
- Forum Commoner
- Posts: 36
- Joined: Thu Sep 02, 2010 12:51 am
Re: Couldn't connect to server
Where should I place the database (or server) ? I use MySQL 5.1 Command line client to create database and I use XAMPP.
Re: Couldn't connect to server
I don't understand the question. Hasn't the database been created already?
-
phpBrandNew
- Forum Commoner
- Posts: 36
- Joined: Thu Sep 02, 2010 12:51 am
Re: Couldn't connect to server
The database has been created using MySQL command line client, let say database 'Animal'. If I want connect to this database, am I using the same way as I posted ?
Re: Couldn't connect to server
The script appears to be correct. Unfortunately, it is impossible to tell which of the two MySQL functions is failing because the two error messages are identical. That is why I hinted that you should replace the "Couldn't connect to server" strings with calls to mysql_error(), which will return a different error message for a server connection failure than for a database selection failure.
-
phpBrandNew
- Forum Commoner
- Posts: 36
- Joined: Thu Sep 02, 2010 12:51 am
Re: Couldn't connect to server
I change the code as follow:
<?php
$users="root";
$host="localhost";
$password="";
$database="team";
$connection="mysql_connect($host,$users,$password)
or die('Couldn't connect to server')";
$result = "mysql_query
('SELECT * FROM members ORDER BY id') or die('error querying database')";
?>
This time I see blank in the browser. Why I couldn't see the table 'members' ?
<?php
$users="root";
$host="localhost";
$password="";
$database="team";
$connection="mysql_connect($host,$users,$password)
or die('Couldn't connect to server')";
$result = "mysql_query
('SELECT * FROM members ORDER BY id') or die('error querying database')";
?>
This time I see blank in the browser. Why I couldn't see the table 'members' ?
Re: Couldn't connect to server
Please use BBCode tags so your code will appear in a box like this:
The script creates six variables. All of them hold strings. There are no function calls. Unused variables equals blank page.
I think you are ignoring what I am telling you or you do not understand.
Code: Select all
<?php
$users = "root";
$host = "localhost";
$password = "";
$database = "team";
$connection = "mysql_connect($host,$users,$password) or die('Couldn't connect to server')";
$result = "mysql_query('SELECT * FROM members ORDER BY id') or die('error querying database')";I think you are ignoring what I am telling you or you do not understand.
-
phpBrandNew
- Forum Commoner
- Posts: 36
- Joined: Thu Sep 02, 2010 12:51 am
Re: Couldn't connect to server
Ya, I really don't understand.
What script should I add in order to have the table appear on the page ?
What script should I add in order to have the table appear on the page ?
-
phpBrandNew
- Forum Commoner
- Posts: 36
- Joined: Thu Sep 02, 2010 12:51 am
Re: Couldn't connect to server
Thanks for the info.