28 Jan 2014

Database connection with PHP (MySQL)


What you need:
  • servername (e.g. localhost)
  • username
  • password
  • databasename

 

1. Fill mysql_connect() with the database information above:

 

1.1 Fill mysql_select_db() with the database name:

 

1.2 Declare 2 variables for both methods above:

We need these variables for checking errors.

 

2. Checking Errors:

 

2.1 Check if the connection was successful:

 

The method mysql_error() displays the connection error. You should always use this to see what you did wrong. 

 

2.2 Check if the selected database exists:

 

3. Success


Your browser will show you this if you did everything right:

No comments:

Post a Comment