MySQL: start connecting to MySQL with PEAR::MDB2


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



Copy this code and paste it in your HTML
  1. // connect DB
  2. $dsn = array(
  3. 'phptype' => 'mysql',
  4. 'username' => '---username---',
  5. 'password' => '---password---',
  6. 'hostspec' => '---host---',
  7. 'database' => '---db name---'
  8. );
  9. $options = array(
  10. 'portability' => MDB2_PORTABILITY_ALL
  11. );
  12. function errorHandler($error){
  13. die( "エラー発生 {$error->getMessage()}" );
  14. }
  15. PEAR::setErrorHandling(PEAR_ERROR_CALLBACK, 'errorHandler');
  16. $mdb2 =& MDB2::connect($dsn, $options);
  17. $sql = 'set names utf8';
  18. $res =& $mdb2->query($sql);
  19. $mdb2->setFetchMode(MDB2_FETCHMODE_ASSOC);

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.