phpDocumentor db
[ class tree: db ] [ index: db ] [ all elements ]

Source for file Hello.php

Documentation is available at Hello.php

  1. <?
  2. /**
  3. * Used to perform a 'Hello World' query against the database
  4. *
  5. * @package db
  6. * @filesource
  7. * @see HTML_DB_DATABASE_PATH.'/Hello.php'
  8. * @copyright (c) http://Finn-Rasmussen.com
  9. * @license http://Finn-Rasmussen.com/license/ myPHP License conditions
  10. * @author http://Finn-Rasmussen.com
  11. * @version 1.9
  12. * @since 21-oct-2005
  13. */
  14.  
  15. $host = 'localhost'; // i.e. localhost
  16. $username = 'username';
  17. $password = 'password';
  18. $database = 'mysql'; // Database must exist
  19. $sql = 'SELECT * FROM user'; // Table must exist
  20.  
  21. print "<html><head><title>Hello.php $host</title></head><body>\r\n";
  22. print "<h4>Expected result</h4>\r\n";
  23. print "mysql_connect($host,$username,$password) : OK<br />\r\n";
  24. print "mysql_select_db($database,Resource id #1) : OK<br />\r\n";
  25. print "mysql_query(SELECT * FROM user,Resource id #1) : (x) OK<br />\r\n";
  26. print "mysql_close(Resource id #1) : OK<br />\r\n";
  27. print "<hr />\r\n";
  28. print "<h4>Found result</h4>\r\n";
  29. $error = false; // Expect no errors
  30.  
  31. print "mysql_connect($host,$username,$password) : ";
  32. $db = mysql_connect($host,$username,$password);
  33. if ($db) {
  34. print "OK<br />\r\n";
  35. } else {
  36. print "<b>Failed</b><br />\r\n";
  37. $error = true;
  38. }
  39.  
  40. if ($db) {
  41. print "mysql_select_db($database,$db) : ";
  42. $rc = mysql_select_db($database,$db);
  43. if ($rc) {
  44. print "OK<br />\r\n";
  45. } else {
  46. print "<b>Failed</b><br />\r\n";
  47. $error = true;
  48. }
  49.  
  50. print "mysql_query($sql,$db) : ";
  51. $rc = mysql_query($sql,$db);
  52. if ($rc) {
  53. print '('.mysql_num_rows($rc).") OK<br />\r\n";
  54. } else {
  55. print "<b>Failed</b><br />\r\n";
  56. $error = true;
  57. }
  58.  
  59. print "mysql_close($db) : ";
  60. $rc = mysql_close($db);
  61. if ($rc) {
  62. print "OK<br />\r\n";
  63. } else {
  64. print "<b>Failed</b><br />\r\n";
  65. $error = true;
  66. }
  67. }
  68. if ($error) {
  69. print "<hr />\r\nmySQL <b>Failed</b>, please check you mySQL configuration:<br />\r\n";
  70. print "<ul>\r\n";
  71. print "<li>host: $host</li>\r\n";
  72. print "<li>username: $username</li>\r\n";
  73. print "<li>password: $password</li>\r\n";
  74. print "<li>database: $database (note: database must exist)</li>\r\n";
  75. print "<li>sql: $sql (note: table must exist)</li>\r\n";
  76. print "</ul>\r\n";
  77. } else {
  78. print "<hr />\r\n<b>Congratulation</b>, your mySQL is up and running<br />\r\n";
  79. print "<ul>\r\n";
  80. print "<li>host: $host</li>\r\n";
  81. print "<li>username: $username</li>\r\n";
  82. print "<li>password: $password</li>\r\n";
  83. print "<li>database: $database (note: database must exist)</li>\r\n";
  84. print "<li>sql: $sql (note: table must exist)</li>\r\n";
  85. print "</ul>\r\n";
  86. }
  87. print "</body></html>\r\n";
  88. ?>

Documentation generated on Thu, 22 Dec 2005 17:09:19 +0100 by phpDocumentor 1.3.0RC3