account = array( "sid" => "[sid]", "auth_token" => "[auth_token]", "registered_phone" => "+[registered_phone]", "verified_phone" => "+14155238886" ); # Define the Twilio client object. $this->twilio = new Client($this->account["sid"], $this->account["auth_token"]); # Define the MySQL database server settings. $this->conn = $conn; $this->table = $table; } # Send a WhatsApp message from the verified phone to the registered phone. public function send_message($text){ $message = $this->twilio->messages ->create("whatsapp:".$this->account["registered_phone"], array( "from" => "whatsapp:".$this->account["verified_phone"], "body" => $text ) ); echo '

WhatsApp Message Send...'; } // Database -> Insert Data: public function insert_new_data($d1, $d2, $d3, $d4, $d5){ $sql = "INSERT INTO `$this->table`(`date`, `temperature`, `humidity`, `egg_count`, `feeder_status`) VALUES ('$d1', '$d2', '$d3', '$d4', '$d5')"; if(mysqli_query($this->conn, $sql)){ return true; } else{ return false; } } // Database -> Create Table public function database_create_table(){ // Create a new database table. $sql_create = "CREATE TABLE `$this->table`( id int AUTO_INCREMENT PRIMARY KEY NOT NULL, `date` varchar(255) NOT NULL, temperature varchar(255) NOT NULL, humidity varchar(255) NOT NULL, egg_count varchar(255) NOT NULL, feeder_status varchar(255) NOT NULL );"; if(mysqli_query($this->conn, $sql_create)) echo("

Database Table Created Successfully!"); } // Obtain the registered data records (results) from the given database table. public function obtain_results(){ $sql = "SELECT * FROM `$this->table`"; $result = mysqli_query($this->conn, $sql); $check = mysqli_num_rows($result); if($check > 0){ $data_array = array(); while($row = mysqli_fetch_assoc($result)){ array_push($data_array, $row); } return $data_array; }else{ $no_data = array([ "date" => "X", "temperature" => "X", "humidity" => "X", "egg_count" => "X", "feeder_status" => "X" ]); return $no_data; } } } // Define database and server settings: $server = array( "name" => "localhost", "username" => "root", "password" => "", "database" => "poultry_feeder", "table" => "entries" ); $conn = mysqli_connect($server["name"], $server["username"], $server["password"], $server["database"]); ?>