Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Database {
- public $hostname = "hostname";
- public $username = "username";
- public $password = "password";
- public $database = "database";
- public function __construct() {
- if( !mysqli_real_connect( $this->hostname, $this->username, $this->password, $this->database ) ) {
- die( "<h1>MySQLi Error:</h1><hr>" . mysqli_connect_error() . "<hr>" );
- }
- }
- public function query( $string ) {
- $q = mysqli_query( $string );
- if( !$q ) { die( "<h1>MySQLi Error:</h1><hr>" . mysqli_error() . "<hr>" ); }
- return $q;
- }
- public function arr( $string, $lazy = false ) {
- return $lazy != false ? mysqli_fetch_array( $this->query( $string ) ) : mysqli_fetch_array( $string );
- }
- public function assoc( $string, $lazy = false ) {
- return $lazy != false ? mysqli_fetch_assoc( $this->query( $string ) ) : mysqli_fetch_assoc( $string );
- }
- public function num( $string, $lazy = false ) {
- return $lazy != false ? mysqli_num_rows( $this->query( $string ) ) : mysqli_num_rows( $string );
- }
- public function escape( $string ) {
- return mysqli_real_escape_string( $string );
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment