1

With this code:

mysql_connect("mysql.webzdarma.cz", "octopus74", "*") or die ("Mysql connect Error>"); 
MySQL_Select_DB("octopus74") or die("Cant choose MySql database.");

It results in: "Mysql connect Error"

1
  • Just to confirm, you're connecting to mysql.webzdarma.cz with the username octopus74 and the password * ? Commented Feb 14, 2011 at 14:43

4 Answers 4

6

Change your die() calls to die(mysql_error()), which will output the ACTUAL reason for the error, which is of far more use than your fixed text.

Sign up to request clarification or add additional context in comments.

3 Comments

I try it and now its return this: "Connection refused"
That means the TCP connection to MySQL failed. Either it's firewalled off, or MySQL's been configured with 'skip-networking', which disables TCP support. If this is on the same physical server as where you're connecting from, try "localhost" instead. Otherwise you'll have to get TCP enabled (or a hole punched in the firewall) in MySQL.
Make sure the MySQL server is actually running, has the database running, and so on. Try connecting via the command line or with whatever client you prefer, see if that works.
4

Source : http://wallstreetdeveloper.com/php-database-connection/

I found a very useful code for connecting with mysql i posted below:

<?php
//Step-1 : Create a database connection
$connection=mysql_connect(“localhost”,”root”,”root”);
if(!$connection) {
    die(“Database Connection error” . mysql_error());
}
//Step-2 : Select a database to use
$db=mysql_select_db(“widget_corp”,$connection);
if(!$db) {
    die(“Database Selection error” . mysql_error());
}
?>
<html>
<head>
<title>Database</title>
</head>
<body>
<?php
 //Step 3 : Perform database Queury
 $result=mysql_query(“select * from subjects”,$connection);
if(!$result) {
    die(“No rows Fetch” . mysql_error());
}

//Step 4 : Use returned data
while($row=mysql_fetch_array($result))
{
     //echo $row[1].” “.$row[2].”<br>”;
    echo $row["menu_name"].” “.$row["position"].”<br>”;
}

?>
</body>
</html>
<?php
//Step 5 : Close Connection
mysql_close($connection);
?>

Comments

2

first are you sure that your mysql username and password are correct? The syntax for mysql connect is:

mysql_connect('your host server', 'mysql_username', 'mysql_password');

The syntax for mysql select db is:

mysql_select_db ('your_database_name');  

Are you sure that your mysql username and mysql database name is the same : "octopus74".

I would recommend to do in this way:

$conn = mysql_connect('localhost', 'mysql_user', 'mysql_password');  
if (!$conn) {  
    die('Not connected : ' . mysql_error());  
}  
// select db  
$db_selected = mysql_select_db('mydbname', $conn);  
if (!$db_selected) {  
    die ('Cannot use database mydbname : ' . mysql_error());  
}  

Comments

0

Open up the server's my.cnf and find this line:

#
# Instead of skip-networking the default is now to listen only on
# localhost which is more compatible and is not less secure.
bind-address        = 127.0.0.1

If it's localhost (127.0.0.1) you won't be able to connect to it. Change it to 0.0.0.0 to allow the server to listen for external connections.

On the other hand, if it's 0.0.0.0 and you can't connect, check that:

  • Server is up (no laughing matter, I've seen these cases)
  • Service / Daemon is up
  • Port is open and you're connecting through the right one: it might have been reassigned.

If all else fails ... use fire and call your SysAdmin.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.