Advertisement
Guest User

Untitled

a guest
Jun 14th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.45 KB | None | 0 0
  1. <?PHP
  2. // Connects to the MySQL database
  3. $dbhost = 'achivements.org.mysql';  // MySQL Host
  4. $dbuser = 'achivements_org';        // MySQL Username
  5. $dbpass = '?????????';          // MySQL Password
  6. $dbname = 'achivements_org';        // MySQL Database
  7. $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('An error occurred while trying to connect to the MySQL database: ' . mysql_error());
  8.  
  9. mysql_select_db($dbname);
  10.  
  11. class MySQL
  12. {
  13.    
  14.     // Prints a row from the MySQL database
  15.     public function get_rows($row_name, $table, $id = false)
  16.     {
  17.         if($id == true)
  18.         {
  19.             $SQL = "SELECT * FROM $table";
  20.             $result = mysql_query($SQL);
  21.            
  22.             if (!$result)
  23.             {
  24.                 echo "Could not successfully run query ($sql) from database: " . mysql_error();
  25.                 exit;
  26.             }
  27.            
  28.             if (mysql_num_rows($result) == 0)
  29.             {
  30.                 echo "No rows found";
  31.             }
  32.             while ($row = mysql_fetch_assoc($result))
  33.             {
  34.                 $data[] = array(id => $row['id'], name => $row[$row_name]);
  35.             }
  36.            
  37.             return $data;
  38.             mysql_free_result($result);
  39.         }
  40.         else
  41.         {
  42.             $SQL = "SELECT * FROM $table";         
  43.             $result = mysql_query($SQL);
  44.            
  45.             if (!$result)
  46.             {
  47.                 echo "Could not successfully run query ($sql) from database: " . mysql_error();
  48.                 exit;
  49.             }
  50.            
  51.             if (mysql_num_rows($result) == 0)
  52.             {
  53.                 echo "No rows found";
  54.             }
  55.        
  56.             while ($row = mysql_fetch_assoc($result))
  57.             {
  58.                 $arr[] = $row[$row_name];
  59.             }
  60.            
  61.             return $data;
  62.             mysql_free_result($result);
  63.         }
  64.     }
  65. }
  66. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement