Advertisement
Echo89

My PHP Framework usage example.

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