Error in mysql_connect() using ZZEE between two PC - php

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.

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.

Related

Remote SQL connection: mysqli_connect(): (HY000/1045): Access denied for user

I have a database that I want to transfer to my remote server from localhost. The file being too big, I wrote the code to copy the table. But the problem the connection is not successful. My code looks like this.
$server_conn=mysqli_connect($db_host,$db_user,$db_pass,$db_name);
if (!$server_conn) {
die("Server Connection Fail: " . mysqli_connect_error());
}
Where $db_host is the ip address of my server.
When I load the script the error I get is
Server Connection Fail: Access denied for user db_user#'117.202.126.83' (using password: YES)
The credentials are correct, the host is correct, and the weirdest part is 117.202.126.83 is my IP address.
I don't know how is it ignoring the host and taking my connection IP address for host. Even when I give the db_host as the IP address of my remote server.
Also, I am running the script using Easy PHP 14.1 running APACHE 2.4.7,MYSQL 5.6.15 and PHP 5.4.24.
What am I missing?
UPDATE: I am not sure if I was stupid or if the hostgator instructions were.
They ask us to add the cpanel username followed by an underscore before the database name and database username.
In the cpanel, the cpanel username is prefixed by force to all user and db names. So in my case, I had the variables as cpanelUsername_cpanelUsername_databaseName and so on.
Thank you guys for your replies
Go to the cpanel where your phpMyAdmin has the access.
Click on Remote MySQL
Add the access host (Your local IP which is running the script)
Then you can get access to remote mysql server.
You can then test the connection using MySQL Workbench ()
are you sure you use the proper external database hostname/ip?

Remote MySQL Connection in PHP

I'm beginning to migrate a software project from being a desktop application to a web application. Currently I am using a local PHP/MySQL connection that is associated with the desktop it is installed on.
I'm hoping to untangle this and am trying to create a MySQL database through my 1and1 account. I had no trouble creating a database and recorded my account information. I'd like to be able to edit this database using PHP scripts on my system. However, I haven't been able to get a working connection string going. When I run the following PHP script:
$hostname="db*********.db.1and1.com";
$database="db*********";
$username="dbo*********";
$password="*********";
$link = mysql_connect($hostname, $username, $password);
I get the following error when I run the script in my webbrowser:
Warning: mysql_connect() [function.mysql-connect]: Unknown MySQL server host 'db*********.db.1and1.com' (11001) in C:\Program Files\xampp\htdocs\Remote_MySQL\rightbid_database_initialize.php on line 74
Connection failed: Unknown MySQL server host 'db*********.db.1and1.com' (11001)
How do I get my local system to recognize the 1and1 server host? Am I structuring my connection string correctly? Is it possible to access a remote server from a locally hosted Windows PHP connection?
Thanks!
I assume what's happening if that 1&1 are blocking any connections coming from outside of their network.
Try connecting using
mysql -h HOST -u USERNAME -p DATABASENAME
Good luck
Make sure the MySQL server on 1and1 will accept connections from remote clients. Not just on localhost, and also make sure port 3306 is open to the server.

Error while connecting to mysql database from php

I have recently started exploring free hosting sites where they provide free mysql and php.
I have created a database and trying to connect to the database from php script. But while running the php. I am getting following error :
Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'a1696486_test '#'localhost' (using password: YES) in /home/a1696486/public_html/myphp/test1.php on line 2
Warning: mysql_select_db() [function.mysql-select-db]: Access denied for user 'a1696486'#'localhost' (using password: NO) in /home/a1696486/public_html/myphp/test1.php on line 3
Any idea whats the problem ?
Regards,
Shankar
I have this issue on our dedicated servers, and the solution for me is to provide the fully qualified domain name rather than 'localhost'. For exmaple, my connection is:
mysqli_connect('dedi81.jnb1.host-h.net', 'user', 'pass', 'db');
Where even though localhost is the same as dedi81.jnb1.host-h.net (MySQL server and web server on one machine) I - for some reason - cannot use 'localhost'.
Another issue may be that on the hosting company you're with, they have not granted to you the correct permissions, or that there is indeed an error with the username and / or password.
You can also try and substitute 'localhost' with the IP address of the MySQL machine.
Kind regards,
Simon

mysql_connect doesn't work on a certain host

I get this everytime I use mysql_connect() no matter what database I choose:
Warning: mysql_connect() [function.mysql-connect]: Can't connect to MySQL server on 'IP' (111) in filename.php on line 17
A MySQL error has occurred: Can't connect to MySQL server on 'IP' (111)
The exact same file works on my personal website fine. I have tried multiple databases hosted on different servers and it always gives that output.
The database itself is hosted on the same server, but using its full IP in mysql_connect(). Using localhost:port doesn't work either as it says:
Warning: mysql_connect() [function.mysql-connect]: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in filename.php on line 17
A MySQL error has occurred: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
But using the IP should work as it has worked calling it via the same file hosted on other servers.
This is the code:
$connect = mysql_connect($db_url,$db_user,$db_pass); // connects
if ($connect == false) exit("A MySQL error has occurred: " . mysql_error());
Now since the file works on other servers i am guessing it is something to do with the server it is on and might need something changed. I don't personally have root access to the server (just my part of the shared host). Is there anything I can do i php, editing the php.ini file or something I should pass on to someone with root access?
Edit: Ok it turns out that the server doesn't have access to outside databases, so thats why the IP didn't work. Thanks for all your answers but we have decided simply to change hosting provider. We need to be able to access an outside database.
This is on a hosting service? Check their documentation, there will be something that tells you where to find mysql. It isn't necessarily localhost.
For example, on startlogic.com, you use: yourdomain.startlogicmysql.com
Can you connect using mysqladmin using the same host, username and password?
mysqladmin -h $db_url -u $db_user -p $db_pass
Replace $db_xxxx with real values.
If that works from the same host as your php script, then sudo to the apache User and try the same test. One of those must be failing.
EDIT: nevermind on sudo part, I noticed that you don't have root access.
Something else to try: Use '127.0.0.1' instead of 'localhost'. I have had issues before where mysql stupidly assumed it could silently change 'localhost:' to '/var/run/mysqld/mysqld.sock'.
Your wording is not very clear, I hope you are not thinking you can connect to the same mysql server from any old web server just because you know the IP address and port number. If the web host is at all competent, they have probably firewalled mysql so it is only accessible through their own web servers.

mysql_connect() is not getting to the correct server

I have a system with a globally open mysql connection to the local server. In one of my files I am opening an additional connection to a remote machine.
Wieldly instead of trying to connect to that machine, I get an access denied message from my ISP (it seems to be trying to connect to the database on that machine).
I am trying to connect using:
$cust_conn = mysql_connect($host,'root','##password##');
I have tried subdomain.domain.com:3306, subdomain.domain.com and ip:3306 as the value for $host.
The wierd this is the response i get:
Warning: mysql_connect(): Access denied for user 'root'#'my.isp.com' (using password: YES) in /var/www/html/report/module/sql_view.php on line 19 Error: Could not connect to database:
Any ideas why this would happen? It seems like for some reason my script is attempting to connect to my ISPs server, instead of the one passed in $host.
The host given in the error message is the host it's trying to connect from, not to.
that hostname in the error (my.isp.com) is your client's host...remote root access is often disabled, or perhaps the pass/host combo is wrong
to add the creds:
http://dev.mysql.com/doc/refman/5.1/en/adding-users.html

Categories