0

I developed a project in PHP and converted it to project.exe using ZZEE PhpExe, It work fine on one PC where the WAMP is installed.

I connected another PC to the main Server using LAN and share the project.exe that was complied. I was able to open the project on the other PC, but it can't connect to MySql. by show this error

Warning: mysql_connect() [function.mysql-connect]: Can't connect to MySQL server on 'localhost' (10061) in/www/inc/connect.php on line 13

I tried to use Firefox to check and it work without Error or Warning by using browsers. I went to change my connect.php server name to the LAN IP. E.g

$hostname = "localhost"; to $hostname = "192.168.1.3";

After the changes I Re-Compile the project, then another warning:

Warning: mysql_connect(): Host 'DESKTOP-VLU1NVA' is not allowed to connect to this MySQL server in C:\xampp\htdocs\clinicx\inc\connect.php on line 13

Please can someone tell me what to do.

  • 1
    The `mysql_` functions are deprecated and shouldn't be used anymore. Instead, use MySQLi or PDO. – AntoineB May 31 '16 at 13:43
  • 1
    Possible duplicate of [Host 'xxx.xx.xxx.xxx' is not allowed to connect to this MySQL server](http://stackoverflow.com/questions/1559955/host-xxx-xx-xxx-xxx-is-not-allowed-to-connect-to-this-mysql-server) – Gerald Schneider May 31 '16 at 13:45
  • 1
    Per @AntoineB's comment, you should avoid using the `mysql_xxx` functions. They have been considered bad practice for well over a decade and have removed from entirely from the latest PHP versions. This means your code will not work if you ever upgrade your PHP version. Fix it now, because it will be much bigger problem for you if you're forced to fix it in a hurry later on. – Simba May 31 '16 at 14:07

1 Answers1

0

You need to grant the remote PC access to the MySQL-server. Check out the GRANT command for MySQL: http://dev.mysql.com/doc/refman/5.7/en/grant.html

A very insecure way to do this is:

GRANT ALL ON *.* to '<a username>'@'192.168.1.%';

Don't use this for production, make sure to grant access to only what is needed and add a password.

Dag Sondre Hansen
  • 2,449
  • 20
  • 22
  • If I add new privilege from phpmyadmin will it work and do I have to change the connect.php config? `$hostname = "localhost"; $username = "root"; $password = ""; $dbh1 = mysql_connect($hostname, $username, $password); $dbh2 = mysql_connect($hostname, $username, $password, true); $dbh3 = mysql_connect($hostname, $username, $password, true); mysql_select_db('clinic_r', $dbh1); mysql_select_db('clinic_x', $dbh2); mysql_select_db('clinic', $dbh3); ` – Adefila Sammy T-k May 31 '16 at 13:54
  • The new (remote) server must connect to the original servers ip-address, not "localhost" (as you wrote yourself in your question), so use $hostname = "192.168.1.3"; With that, the following should give you access: GRANT ALL ON \*.\* to 'root'@'192.168.1.%'; – Dag Sondre Hansen May 31 '16 at 14:02