Aziz-Rahman

Function connections with mysqli

Apr 16th, 2015
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.45 KB | None | 0 0
  1. ================ File connection.php ====================
  2. <?php
  3.  
  4. function connectionDB() {
  5.     global $mysqli;
  6.  
  7.     $mysqli = mysqli_connect( "localhost", "root", "", "mahasiswa" );
  8.  
  9.     if ( mysqli_connect_errno() ) {
  10.         printf( "Connect failed: %s\n", mysqli_connect_error() ;
  11.         exit();
  12.  
  13.     }
  14. }
  15. ?>
  16.  
  17. ================== Other files =====================
  18. <?php  
  19. include "connection.php";
  20. connectionDB();
  21.  
  22. $sql = "INSERT INTO Bla bla... ";
  23.  
  24. //etc ..
  25. ?>
Advertisement
Add Comment
Please, Sign In to add comment