Posted By

gdonald on 09/26/06


Tagged

mysql mysqli connect


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

jleblanc
dmarten
vali29


php mysql/mysqli connect


 / Published in: PHP
 

  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. if( mysqli_connect_errno() )
  22. {
  23. die( 'Cannot connect to database ' . mysqli_connect_error() );
  24. }
  25. }
  26. else
  27. {
  28. die( 'MySQL extension is not loaded' );
  29. }

Report this snippet  

You need to login to post a comment.