Hazak Posted March 20, 2018 Posted March 20, 2018 I'm testing a remote connection to my Mysql DB and table. I followed the basic procedure: 1 - I created DB ("employee101") by Mysql wizard.2 - I created employee_data table by Myphpdamin.3 - I created two DB users ("hazak" (cpanel user) and "remcon".4 - I set users access and rights to "employee101" DB. 5 - I built two PHP scripts to remotely access Db and table, and put them in "hazak" public_html directory, as follows: 1 - conn.php (connection):<?php$db_name = "hazak_employee101";$mysql_username = "hazak";//$mysql_username = "remcon";//$mysql_password = "&cx=Q******";$mysql_password = "al********";$server_name = "localhost:3306";$conn = mysqli_connect($server_name, $mysql_username, $mysql_password, $db_name);if($conn){echo "connection success";}else{echo "connection not success";}?> 2 - login.php (login): <?phprequire "conn.php";$user_name = $_POST["user_name"];$user_pass = $_POST["password"];$mysql_qry = "select * from employee_data where username like '$user_name' and password like '$user_pass';";$result = mysqli_query($conn, $mysql_qry);if(mysqli_num_rows($result) > 0){$row = mysqli_fetch_assoc($result);$name = $row["name"]; echo "login success - user ".$name;}else{echo "login not success";}mysqli_close($conn)?> 6 - Remotely run the script. First using "hazak" user set in conn.php and second, using "remcon" user in the same script.I got the same error message (bellow) and when I created an email acoount to "hazak" (cpanel) user the message gone away and I could remotely connect to DB and access "employee_data" table. but the same didn't happened to the "remcon" user. Since I could't find reference to this error on heliohost.org Mysql pages I´m not sure about what is the error cause. Can anybody tell the possible cause/solution for this error and help me? Error message: Warning: mysqli_connect(): (HY000/1045): Access denied for user 'remcon'@'localhost' (using password: YES) in /home/hazak/public_html/remcon/conn.php on line 8
sagnik Posted March 21, 2018 Posted March 21, 2018 Maybe the database you are trying to access it has been created by another user/with a different password or you don't have permission to access the database. Check the details in cPanel > MySQL Databases.
Hazak Posted March 21, 2018 Author Posted March 21, 2018 Sagnik, yes the database was crested by "hazak" user (cpanel admin) but I added "remcon" as DB user and set all access rights as I said before.
sagnik Posted March 22, 2018 Posted March 22, 2018 Do you get any of the message as defined here:if($conn){echo "connection success";}else{echo "connection not success";}If yes, then modify it to:if($conn){echo "connection success";}else{echo "connection not success: ".mysqli_error($conn);} and see what mysql says. 1
wolstech Posted March 22, 2018 Posted March 22, 2018 @Sagnik: The access denied error he's getting will always make $conn false. I would try changing the password on the mysql user next. Also, this line would never be valid: //$mysql_username = "remcon"; Except for the cPanel default mysql user (the one that's the same as your cpanel username), all MySQL users will be prefixed with cpanelusername_, so it should be It should be hazak_remcon, assuming hazak is your cPanel username.
Hazak Posted March 22, 2018 Author Posted March 22, 2018 sagnik: I did conn.php modification as you recommended.Basically I got the same result and no new clue was showed, as follows: ( ! ) Warning: mysqli_connect(): (HY000/1045): Access denied for user 'remcon'@'179.157.27.166' (using password: YES) in C:\wamp64\www\conn_remx1.php on line 6 Call Stack # Time Memory Function Location 1 0.0007 235624 {main}( ) ...\conn_remx1.php:0 2 0.0007 236424 mysqli_connect ( ) ...\conn_remx1.php:6 ( ! ) Warning: mysqli_error() expects parameter 1 to be mysqli, boolean given in C:\wamp64\www\conn_remx1.php on line 11 Call Stack # Time Memory Function Location 1 0.0007 235624 {main}( ) ...\conn_remx1.php:0 2 5.3416 237160 mysqli_error ( ) ...\conn_remx1.php:11 connection not success:
wolstech Posted March 22, 2018 Posted March 22, 2018 That's running on your local computer on WAMP...the file needs to actually be on our server to work with the settings you listed. If you want to run the scripts from a server that's not ours, you need to enable remote mysql in cPanel (add the remote server's IP, or % to allow any), then use johnny.heliohost.org instead of localhost for the hostname.
Hazak Posted March 22, 2018 Author Posted March 22, 2018 The Root Admin recommendation works remotely from my Wampserver php script. (user name prefix)Now I´m going to test running directly on my heliohost.org www directory.I hope there will be no problem.Thanks mates.
Hazak Posted March 22, 2018 Author Posted March 22, 2018 (edited) Root Admin:When I run the new conn.php script (changing user name to "hazak_remcon") in my www heliohost.org directory (using localhost as host), I got the same success result.Thanks for support. Edited March 22, 2018 by Hazak
wolstech Posted March 22, 2018 Posted March 22, 2018 You're welcome. Please let us know if you need anything else.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now