Jazza Posted June 29, 2014 Share Posted June 29, 2014 (edited) 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 June 29, 2014 by Jazza Link to comment Share on other sites More sharing options...
Ixzion Posted June 29, 2014 Share Posted June 29, 2014 (edited) 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 June 29, 2014 by Ixzion Link to comment Share on other sites More sharing options...
Jazza Posted June 30, 2014 Author Share Posted June 30, 2014 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 More sharing options...
scout1idf Posted June 30, 2014 Share Posted June 30, 2014 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 More sharing options...
justsomeguy Posted June 30, 2014 Share Posted June 30, 2014 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 More sharing options...
Alken Jarge Posted July 6, 2014 Share Posted July 6, 2014 mysql_connect("localhost","root",""); mysql_select_db("database name"); Link to comment Share on other sites More sharing options...
justsomeguy Posted July 7, 2014 Share Posted July 7, 2014 Do not use the mysql extension for anything, ever. It is correct to use mysqli, never mysql. Link to comment Share on other sites More sharing options...
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