PageRenderTime 38ms CodeModel.GetById 12ms RepoModel.GetById 1ms app.codeStats 0ms

/hphp/test/zend/bad/ext/mysql/tests/mysql_select_db.php

http://github.com/facebook/hiphop-php
PHP | 59 lines | 36 code | 19 blank | 4 comment | 12 complexity | 90622d42634c05009e0d37f3fa250358 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-2-Clause, BSD-3-Clause, MPL-2.0-no-copyleft-exception, MIT, LGPL-2.0, Apache-2.0
  1. <?php
  2. include_once "connect.inc";
  3. $tmp = NULL;
  4. $link = NULL;
  5. if (false !== ($tmp = @mysql_select_db($link)))
  6. printf("[001] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
  7. if (!$link = my_mysql_connect($host, $user, $passwd, $db, $port, $socket))
  8. printf("[002] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n",
  9. $host, $user, $db, $port, $socket);
  10. if (!is_null($tmp = @mysql_select_db($db, $link, "foo")))
  11. printf("[003] Expecting NULL, got %s/%s\n", gettype($tmp), $tmp);
  12. /* does not make too much sense, unless we have access to at least one more database than $db */
  13. if (!mysql_select_db($db, $link))
  14. printf("[004] Cannot select DB %s, [%d] %s\n", $db, mysql_errno($link), mysql_error($link));
  15. if (!$res = mysql_query("SELECT DATABASE() AS dbname", $link))
  16. printf("[005] [%d] %s\n", mysql_errno($link), mysql_error($link));
  17. if (!$row = mysql_fetch_assoc($res))
  18. printf("[006] [%d] %s\n", mysql_errno($link), mysql_error($link));
  19. if ($row['dbname'] !== (string)$db)
  20. printf("[007] Expecting database '%s', found '%s'\n", $db, $row['dbname']);
  21. var_dump($row['dbname']);
  22. mysql_free_result($res);
  23. if (mysql_select_db('mysql', $link)) {
  24. // Yippie, a second database to play with - that's great because mysql_select_db
  25. // ($db) was done by mysql__connect() already and the previous test
  26. // was quite useless
  27. if (!$res = mysql_query("SELECT DATABASE() AS dbname", $link))
  28. printf("[008] [%d] %s\n", mysql_errno($link), mysql_error($link));
  29. if (!$row = mysql_fetch_assoc($res))
  30. printf("[009] [%d] %s\n", mysql_errno($link), mysql_error($link));
  31. if (strtolower($row['dbname']) !== 'mysql')
  32. printf("[010] Expecting database 'mysql', found '%s'\n", $row['dbname']);
  33. mysql_free_result($res);
  34. }
  35. var_dump(mysql_select_db('I can not imagine that this database exists', $link));
  36. mysql_close($link);
  37. if (false !== ($tmp = mysql_select_db($db, $link)))
  38. printf("[012] Expecting boolean/false, got %s/%s\n", gettype($tmp), $tmp);
  39. print "done!\n";
  40. ?>