milan Posted June 2, 2017 Posted June 2, 2017 Hi eveyone! I am using the following code to connect to my mySQL database: <?php // Create connection$conn = mysqli_connect('localhost', 'database_user_name', 'database_password');// Check connectionif (!$conn) {die("Connection failed: " . mysqli_connect_error());} mysqli_select_db($conn,"database_name"); ?> I tried several variants of this, replacing parameters:mysqli_connect('tommy.heliohost.org', 'database_user_name', 'database_password');mysqli_connect('localhost', 'database_name', 'database_password');mysqli_connect('tommy.heliohost.org', 'database_name', 'database_password'); None of those seem to work. Could you please help me out figure out which host, username and password I should use to make this work. To note, my website is currently hosted on tommy.heliohost.org. Is this also true for mySQL database? In the next step I will be trying to connect remotely and it would be cool if you also let me know what the hostname for the external world looks like, and how do i log onto it. Thank you very much! Best,Milan
Krydos Posted June 2, 2017 Posted June 2, 2017 To connect from a script running on the server: $con = new mysqli('localhost', 'milanan_user', 'bestpasswordever', 'milanan_database'); To connect from a remote script just use tommy.heliohost.org as the host instead of localhost. 1
milan Posted June 2, 2017 Author Posted June 2, 2017 Hey, Krydos, thanks! It worked on the local domain!When I try to connect remotely I get the following error:XMLHttpRequest cannot load [path to my php file connect file]Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https Any advice on how to go from there? Thanks a lot! Best,Milan
Krydos Posted June 2, 2017 Posted June 2, 2017 Have you enabled remote connections to mysql? https://tommy.heliohost.org:2083/frontend/paper_lantern/sql/managehost.html
milan Posted June 5, 2017 Author Posted June 5, 2017 Hey Krydos, Yes I enabled remote connections by putting the wildcard % in the list of hosts - this is an error that popped up regardless of that. Best,Milan
milan Posted June 7, 2017 Author Posted June 7, 2017 Dear Krydos, Here's the error once again with the actual path to my local php file: XMLHttpRequest cannot load file:///C:/Users/milan/JavaScript/MySQL_posting/heliohost_mySQL_connectMethod_remote/userInfo.php. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https. Best,Milan
Krydos Posted June 7, 2017 Posted June 7, 2017 That's a security error. Read this https://stackoverflow.com/questions/10752055/cross-origin-requests-are-only-supported-for-http-error-when-loading-a-local Imagine if that is allowed and a webapp whereby the author of the page uses something like load('file://C:/users/user/supersecret.doc') and then upload the content to their server using ajax etc.Basically, if the file is hosted via https/http/etc you can assume the owner of the file understands that it's being shared. If it's a path like file://c:/ that means it could be ANYTHING on your harddrive, which you don't necessarily want someone on the internet being able to access.
milan Posted June 8, 2017 Author Posted June 8, 2017 Hi Krydos, Thanks for your explanation, that is very helpful. I tried some of the followup suggestions from the stackoverflow post: running a local server using python, or using the npm http-server in windows command line, but those servers do not support the ajax post method. I also tried opening chrome with --allow-file-access-from-files but that doesn't seem to change anything. Do you have any recommendations/pointers for a simple solution? Thanks a lot! Milan
Krydos Posted June 8, 2017 Posted June 8, 2017 Apache runs on windows. https://httpd.apache.org/docs/current/platform/windows.html#down
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