Advertisement
Guest User

Untitled

a guest
Sep 15th, 2017
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.92 KB | None | 0 0
  1. <?php
  2. /*
  3.  * To change this template, choose Tools | Templates
  4.  * and open the template in the editor.
  5.  */
  6. function connect_mysql($mysql_host, $mysql_user, $mysql_password){  //connect to mysql database, or close connection and display error
  7.  
  8.     $connect_mysql = mysql_connect($mysql_host, $mysql_user, $mysql_password);
  9.    
  10.     if (!$connect_mysql){
  11.         die('Could not connect: ' . mysql_error());
  12.     }
  13.  
  14.     return ( $connect_mysql );
  15. }
  16.  
  17. function select_db($mysql_db, $connect_mysql){  //select the database we are going to be using
  18.    
  19.     $select_db = mysql_select_db($mysql_db, $connect_mysql);
  20.    
  21.     if (!$select_db){
  22.       die ('Could not select db : '. mysql_error());
  23.     }
  24. }
  25.  
  26. $mysql_host = 'localhost';
  27. $mysql_user = 'root';
  28. $mysql_password = 'asdf!';
  29. $mysql_db = 'asdf';
  30.  
  31. $connect_mysql = connect_mysql($mysql_host, $mysql_user, $mysql_password);
  32. select_db($mysql_db, $connect_mysql);
  33. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement