Jump to content

Recommended Posts

Posted

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 connection
if (!$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

 

 

 

 

 

Posted

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.
  • Like 1
Posted

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

Posted

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

 

Posted

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

Posted

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.
Posted

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...