Jump to content

I can't connect to mysql database


Jazza

Recommended Posts

Hi

 

I am trying to connect to a mysql database through phpmyadmin. I have followed the steps in this video

and still no luck.

 

 

 

 

This is my code;

 

<?phpDEFINE ('DB_USER' , 'jazza' );DEFINE ('DB_PSWD' , 'jarrod');DEFINE ('DB_HOST' , 'localhost:8889');DEFINE ('DB_NAME' , 'ask');$dbcon = mysqli_connect(DB_HOST, DB_PSWD, DB_USER, DB_NAME);if (!$dbcon) { die('error connecting to database');}echo 'you have connected succesfully' ;?>

 

 

In the database 'question' I have created a table called 'ask.' I have created a user 'jazza' and password 'jarrod'. On the top of the page it says 'server:8889'.

When I try to test it on my server through dreamweaver, it says 'error connecting to database'.

 

 

I can't figure out where I went wrong. Can anyone help me out?

 

 

 

Thanks

Edited by Jazza
Link to comment
Share on other sites

What you need for DB_NAME is not 'ask'. That is the name of the table. You need to use the database name, which you said was 'question'.

 

Also, you should never post your username/password publically. I'd recommend changing them.

Edited by Ixzion
Link to comment
Share on other sites

What you need for DB_NAME is not 'ask'. That is the name of the table. You need to use the database name, which you said was 'question'.

 

Also, you should never post your username/password publically. I'd recommend changing them.

Still no luck connecting.

Link to comment
Share on other sites

Just a guess, but you have them out of order. You have...

$dbcon = mysqli_connect(DB_HOST, DB_PSWD, DB_USER, DB_NAME);
...and it should be...
$dbcon = mysqli_connect(DB_HOST , DB_USER , DB_PSWD , DB_NAME);
I'm pretty sure that it matters what order you put them in.....Hope it helps.
Link to comment
Share on other sites

Remove the port number. Unless you changed MySQL to listen on port 8889, that is not the correct port. Leave the port off and see if it connects on the default port (3306). If not, then you need to figure out which port MySQL is listening on. It will not be the same port as HTTP.

Link to comment
Share on other sites

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