php mysql/mysqli connect


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. if( in_array( 'mysql', $GLOBALS[ 'loaded_extensions' ] ) )
  2. {
  3. if( $GLOBALS[ 'dbHandle' ] = mysql_connect( $GLOBALS[ 'DB_HOST' ],
  4. $GLOBALS[ 'DB_USER' ],
  5. $GLOBALS[ 'DB_PASS' ] ) )
  6. {
  7. mysql_select_db( $GLOBALS[ 'DB_DB' ], $GLOBALS[ 'dbHandle' ] );
  8. }
  9. else
  10. {
  11. die( 'Cannot select database ' . $GLOBALS[ 'DB_DB' ] . ': ' . mysql_error() );
  12. }
  13. }
  14. elseif( in_array( 'mysqli', $GLOBALS[ 'loaded_extensions' ] ) )
  15. {
  16. $GLOBALS[ 'dbHandle' ] = mysqli_connect( $GLOBALS[ 'DB_HOST' ],
  17. $GLOBALS[ 'DB_USER' ],
  18. $GLOBALS[ 'DB_PASS' ],
  19. $GLOBALS[ 'DB_DB' ] );
  20.  
  21. {
  22. die( 'Cannot connect to database ' . mysqli_connect_error() );
  23. }
  24. }
  25. else
  26. {
  27. die( 'MySQL extension is not loaded' );
  28. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.