Guest User

Untitled

a guest
Jun 22nd, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.66 KB | None | 0 0
  1. <?php
  2. //Start Class
  3. class database {
  4.  
  5. // Define Varibles
  6. public $mysql;
  7. public $host = "localhost";
  8. public $username = "root";
  9. public $password = "";
  10. public $dbname = "db";
  11.  
  12. //Mail Varibles
  13. public $site = "SiteName";
  14.  
  15. // Start Connection
  16. function __construct(){
  17. //Start the Database Connection
  18. if( $this->MySQL = new mysqli($this->host, $this->username, $this->password, $this->dbname) or die("There was a problem connecting to the Database.")){
  19. echo "Connected to Database";
  20. }
  21. }
  22.  
  23. //Grap the Tables From the Database
  24. function get_tables($sql){
  25. if(($results = $this->MySQL->query($sql)) !=NULL){
  26. // echo $results->num_rows();
  27. while($row = $results->fetch_object()){
  28. $users[] = $row->name;
  29. $emails[] = $row->email;
  30. }
  31. }else{
  32. echo "Rows do not exists in Connected Databse!";
  33. }
  34. }
  35.  
  36. //Update Database
  37. function update_tables($name, $email){
  38. if(!empty($_POST['submit'])) {
  39. $name = $_POST['name'];
  40. $email = $_POST['email'];
  41. $query = "INSERT INTO emailsystem VALUES('', '$name', '$email')";
  42.  
  43. if($updateDb = $this->MySQL->query($query) or die($this->MySQL->error)) {
  44. echo "Congrats!";
  45. }
  46.  
  47. }
  48. }
  49.  
  50. //Auto Mail All Users
  51. function AutoMail(){
  52. if(!empty($_POST['submitMail'])){
  53. mail($emails, $this->site . ' Has Opened!', $this->message , 'From' . $this->$site) ;
  54. echo "All Users have been mailed!";
  55. }else{
  56. echo "Meh, Something went wrong!";
  57. }
  58. }
  59.  
  60. //Destroy Connection
  61. function __destruct(){
  62. //Close the Database Connection
  63. $this->MySQL->close();
  64. }
  65. }
  66. ?>
Add Comment
Please, Sign In to add comment