Skip to content

Instantly share code, notes, and snippets.

@evgv
Created September 23, 2016 08:38
Show Gist options
  • Select an option

  • Save evgv/4dc2e4ae601917add802ac75f1ac189c to your computer and use it in GitHub Desktop.

Select an option

Save evgv/4dc2e4ae601917add802ac75f1ac189c to your computer and use it in GitHub Desktop.
PHP. Database connection

Database connection

To store data, you would need a database. In this case we would be using MySQL database.

 <?php
    $DBNAME = 'dbname';
    $HOST   = 'localhost';
    $DBUSER = 'dbuser';
    $DBPASS = 'dbpass';
    
    $CONNECT = mysql_connect($HOST,$DBUSER,$DBPASS);
    if(!$CONNECT) {
    	echo 'MySQL Error: '.mysql_error();
    }
    
    $SELECT = mysql_select_db($DBNAME);
    if(!$SELECT) {
    	echo 'MySQL Error: '.mysql_error();
    }
  ?>

In the highlighted lines above, you would have to specify your own server database details.

You can save the above file as config.php and you would have to include that file in all pages where you need database connectivity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment