Viewed   100 times

I have the following php code to connect to my mysql DB.

mysql_connect( "myserver.com" , "root", "redhat","datastore") or die(mysql_error()); 

when I ran this code I got the error saying:

Warning: mysql_connect(): Host '10.21.21.10' is not allowed to connect to this MySQL server in C:xampphtdocsinventorynet.php on line 20
Host '10.21.21.10' is not allowed to connect to this MySQL server

But the IP of myserver.com when I did ping myserver.com in command prompt it gave 10.25.15.95

,so I Modified the code to:

mysql_connect( "10.21.21.10" , "root", "redhat","datastore") or die(mysql_error()); 

the same error repeated.

Then i changed my code to:

mysql_connect( "10.25.15.95" , "root", "redhat","datastore") or die(mysql_error()); 

the error was

Warning: mysql_connect(): A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. in C:xampphtdocsinventorynet.php on line 20
A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. 

Please help me in solving this..

Thanks in advance...

 Answers

2

At your mysql server:

mysql> use mysql;

mysql> CREATE USER 'root'@'client_ipaddress' IDENTIFIED BY 'redhat';

mysql> GRANT ALL PRIVILEGES ON . TO 'root'@'client_ipaddress' WITH GRANT OPTION;

Saturday, September 24, 2022
 
ehsanul
 
3

You're missing quotes around your string values:

$sql = "INSERT INTO people (person_id, name, username, password, email, salt)
            VALUES ($person_id, '$name', '$username', '$password', '$email', '$salt')";
Tuesday, October 25, 2022
1
  • firewall of the server must be set-up to enable incomming connections on port 3306
  • you must have a user in MySQL who is allowed to connect from % (any host) (see manual for details)

The current problem is the first one, but right after you resolve it you will likely get the second one.

Monday, August 1, 2022
5

Note:The steps provided here are only for Linux, you might be using some other OS then use respective editor and commands

MySQL stores error message file at /usr/share/mysql/english/errmsg.sys where english is the language you want to use.

Note:You need to have super user privileges

Step 1. Take backup of existing errmsg.sys (so that you can revert if some problem occured

  $sudo cp /usr/share/mysql/english/errmsg.sys ~/errmsg.sys.bkp

Step 2. Open /usr/share/mysql/english/errmsg.sys in vi editor.

$sudo vi /usr/share/mysql/english/errmsg.sys

Step 3. Search for "You have an" in errmsg.sys

in vi editor for searching try this way-->  /You have an [press enter]

It will get you to the string "You have an error...." as show in screen-shot

Step 4. Edit that error message as per your need. I've deleted string You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the and kept just right syntax to use

Check below screen-shot.

Step 5. Save and Exit.

in vi editor to save and exit-->   :x! [press enter]     here ! is added to override read-only file

Step 6. Restart mysql service.

$sudo mysql restart

step 7. check error message (I'm checking in phpMyAdmin)

In this answer I've updated error message You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near... similarly you can update other standard error message as well.

Hope it helped ! :D

Monday, November 14, 2022
1
  1. Yes, you can have multiple database connections. You are not opening a database, you are opening a database connection. The database is 'open' (i.e. running) all of the time, generally speaking, whether you are connected to it or not.
  2. Depends... if you only have one open connection on a page, then you don't need to close it because it will automatically close when PHP is done. If you have many, then you could potentially make the database server slower, or make the database server run out of available connections (it can only have a certain number of connections open at the same time). That said, most modern database servers can handle hundreds of concurrent connections.
  3. Optional, but recommended. It's not a big deal for small-medium projects (i.e. if you have less than 100 concurrent visitors at any given time, you probably won't have any issues regardless). Since you have many thousand visitors per minute, you should actively close the database connection as soon as you are done with it, to free it up as soon as possible.
Monday, November 7, 2022
 
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :