Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //Start Class
- class database {
- // Define Varibles
- public $mysql;
- public $host = "localhost";
- public $username = "root";
- public $password = "";
- public $dbname = "db";
- //Mail Varibles
- public $site = "SiteName";
- // Start Connection
- function __construct(){
- //Start the Database Connection
- if( $this->MySQL = new mysqli($this->host, $this->username, $this->password, $this->dbname) or die("There was a problem connecting to the Database.")){
- echo "Connected to Database";
- }
- }
- //Grap the Tables From the Database
- function get_tables($sql){
- if(($results = $this->MySQL->query($sql)) !=NULL){
- // echo $results->num_rows();
- while($row = $results->fetch_object()){
- $users[] = $row->name;
- $emails[] = $row->email;
- }
- }else{
- echo "Rows do not exists in Connected Databse!";
- }
- }
- //Update Database
- function update_tables($name, $email){
- if(!empty($_POST['submit'])) {
- $name = $_POST['name'];
- $email = $_POST['email'];
- $query = "INSERT INTO emailsystem VALUES('', '$name', '$email')";
- if($updateDb = $this->MySQL->query($query) or die($this->MySQL->error)) {
- echo "Congrats!";
- }
- }
- }
- //Auto Mail All Users
- function AutoMail(){
- if(!empty($_POST['submitMail'])){
- mail($emails, $this->site . ' Has Opened!', $this->message , 'From' . $this->$site) ;
- echo "All Users have been mailed!";
- }else{
- echo "Meh, Something went wrong!";
- }
- }
- //Destroy Connection
- function __destruct(){
- //Close the Database Connection
- $this->MySQL->close();
- }
- }
- ?>
Add Comment
Please, Sign In to add comment