Dov_B
asked on
I need help getting a php file to run on my website
I have a website hosted by godaddy having difficulty getting php to interact with a mysql database on my site
<?php
$con=mysqli_connect("localhost.com","d","scores123!");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
// Create database
$sql="CREATE DATABASE my_db";
if (mysqli_query($con,$sql)) {
echo "Database my_db created successfully";
} else {
echo "Error creating database: " . mysqli_error($con);
}
?>
I placed it this code in a file and place it a folder on my website but it takes a million years for it to run and then it errors out
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
oh ok how do I create a table in a databse that already exists
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
<?php
// Create connection
$con=mysqli_connect("localhost","d2","scores123!","scores2");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
?>
error acsses denied
Check your username and password are correct
Whats the exact error message?
Whats the exact error message?
ASKER
Failed to connect to MySQL: Access denied for user 'd2'@'localhost' (using password: YES)
Then the username is wrong.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Dave is probably right about the hostname - I don't know
http://support.godaddy.com/help/article/3323/locating-your-database-connection-strings
http://support.godaddy.com/help/article/3323/locating-your-database-connection-strings
I'm not familiar with that screenshot. That does not exist on either of my Godaddy hosting accounts. You need to get the correct hostname, either by IP address or name, to put in your connections statement.
I've never seen Cpanel or Plesk on Godaddy hosting so you might have that. The link that Gary shows says Cpanel does use 'localhost'.
I've never seen Cpanel or Plesk on Godaddy hosting so you might have that. The link that Gary shows says Cpanel does use 'localhost'.
This is a basic and fundamental question, one that almost every single GoDaddy client would face. As such it would have been asked of GoDaddy thousands of times. Have you called GoDaddy technical support and asked them to send you the link to the standard answer they give to new clients? If not, please do that! And then post the link here so we can see what they gave you for guidance. We can probably fill in any blanks that remain unclear after you've seen the hosting company's recommendation.
If they can't help, you might want to consider moving to another hosting company. I use and am pleased to recommend ChiHost.com. I have also had good experiences with Hostagator and LiquidWeb. I do not recommend either GoDaddy or SiteGround. But YMMV and GoDaddy may be able to help you.
If they can't help, you might want to consider moving to another hosting company. I use and am pleased to recommend ChiHost.com. I have also had good experiences with Hostagator and LiquidWeb. I do not recommend either GoDaddy or SiteGround. But YMMV and GoDaddy may be able to help you.
ASKER
Error creating database: Access denied for user 'd2'@'localhost' to database 'my_db'