Advertisement
Echo89

My PHP Framework usage example v2.

Sep 23rd, 2013
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.26 KB | None | 0 0
  1. <?php
  2.  
  3. // Include necessary files.
  4. require_once("./App/Class.file.php");
  5. require_once("./App/Class.config.php");
  6. require_once("./App/Class.lang.php");
  7. require_once("./App/Class.database.php");
  8.  
  9. // Open a file, called Text.txt, and allow reading and writing (TRUE, TRUE).
  10. // You can also allow the appending and file creating by adding the
  11. // appropriate "TRUE/FALSE, TRUE/FALSE" after the read/write boolean options.
  12. $file = File::Open("./Test.txt", TRUE, TRUE);
  13.  
  14. // If there is something wrong with the file, it will echo the error here and continue.
  15. if($file->classType == "Message")
  16. {
  17.     if($file->type == "Error")
  18.     {
  19.         echo $file->message;
  20.     }
  21. }
  22. else
  23. {
  24.     $file->Write("Hello, World!");
  25.  
  26.     // Fetch contents of the file.
  27.     // the reason it's echoign the "->message" is because it sends all data/error/success messgaes
  28.     // to a log so it can be logged when desired. So the GetContents() function returns a Message
  29.     // with type "Data" and the message as the file content. This way, we can see in the log exactly
  30.     // what is happening and where.
  31.     echo $file->GetContents()->message;
  32.  
  33.     // Close the file.
  34.     $file->Close();
  35. }
  36.  
  37. // This is how you fetch an option from the config.
  38. echo Config::Fetch("SiteName")->message;
  39.  
  40. // This is how you get a line from a language file, and then you
  41. // replace the marker [file] with "./Example.txt".
  42. echo Lang::Get("file.FileNoExist", array("file" => "./Example.txt"))->message;
  43.  
  44. // Open a DB connection
  45. $db = Database::Connect("localhost", "root", "password");
  46.  
  47. // make a query and echo the output with my query constructor.
  48. $query1 = $db->NewQuery()
  49.             ->Select(array("id", "username"))
  50.             ->From(array("example_table"))
  51.             ->Where(array("first_name" => "Caelan", "last_name" => "Stewart"));
  52. // Execute the query above.
  53. $output = $db->ExecQuery($query1);
  54. print_r($db->FetchArray($output->message));
  55.  
  56. // Insertion constructor, accepts strings, numbers, boolean.
  57. $query2 = $db->NewQuery()
  58.             ->Insert("SomeTable", array(
  59.                 "Column1" => "Column1 Value",
  60.                 "Column2" => 1234,
  61.                 "Column3" => FALSE
  62.             );
  63. $db->ExecQuery($query2);
  64.  
  65. // Custom SQL query
  66. $query3 = $db->NewQuery()
  67.             ->Custom("SELECT * FROM `users` WHERE `id` = 56");
  68. $db->ExecQuery($query3);
  69.            
  70. // There you have it, that's my system so far...
  71.  
  72. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement