Advertisement
Guest User

Untitled

a guest
Aug 7th, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.91 KB | None | 0 0
  1. class database_statements{
  2. var $error_in_connection = 'Unable to connect to database at this time.';
  3.  
  4. function database_connection(){
  5. try{
  6. // Establishes a database connection
  7. $dsn = 'mysql:host=localhost; dbname=data; charset=latin1';
  8. $username = 'root';
  9. $password = '';
  10. $connection = new PDO($dsn, $username, $password);
  11. return $connection;
  12. }
  13. catch(Exception $ex){}
  14. }
  15.  
  16. function database_crud($statement, $value = array()){
  17. // ...passes the sql statements and insert the value into the array
  18. // ... the function performs CRUD functions
  19. try {
  20. $db = $this->database_connection();
  21. $insert_data = $db->prepare($statement);
  22. for ($i = 1; $i <= count($value); $i++){
  23. $insert_data->bindValue($i, $value[$i-1]);
  24. }
  25. $insert_data->execute();
  26. }
  27. catch (Exception $ex) {
  28. echo $this->error_in_connection;
  29. }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement