Connect to Database - PHP Sequential Approach


SUBMITTED BY: YouKnowNothing

DATE: Jan. 11, 2016, 12:27 p.m.

FORMAT: PHP

SIZE: 508 Bytes

HITS: 1399

  1. <?php
  2. //This script connects to the database
  3. //Server information
  4. $server = "servername"; //e.g. localhost:8889
  5. $user = "username";
  6. $pass = "password";
  7. //Initiate connection
  8. $conn = mysqli_connect($server, $user, $pass);
  9. if (!$conn){
  10. die("Connection to server failed: ".mysqli_connect_error());
  11. }
  12. echo "Connected to server";
  13. //Connect to database
  14. $db = mysql_select_db($conn, "database name");
  15. if (!$db){
  16. die("Database failed: ".mysqli_connect_error());
  17. }
  18. echo "Connected to DB";
  19. ?>

comments powered by Disqus