Question: Part 2 The first part should make call to every public function in second part. as a hint- add the calls tp the member function

include('mysql.php');

echo "Welcome to our first MySQL class shell ";

$mysql = new MySQL('host', 'user', 'password', 'database');

try{

$posts = $mysql->get('posts'); // pretend that there is a table 'posts'

print_r($posts);

echo $mysql->number_rows(); // number of rows returned

}catch(Exception $e){

echo 'Caught exception: ', $e->getMessage();

}

?>

Part 2

class Mysql {

private $link = null;

private $info;

private $connection_info;

private $where;

private $limit;

private $order;

static private $dummyQueryResponse = array("dummy Row 1", "dummy Row 2");

function __construct($host, $user, $pass, $db) {

$this->connection_info = array('host' => $host, 'user' => $user, 'pass' => $pass, 'db' => $db);

$this->info = array(

'last_query' => null,

'num_rows' => null,

'insert_id' => null

);

}

function __destruct(){

if(is_resource($this->link)) mysql_close(self::$link);

}

public function set($field, $value){

$info[$field] = $value;

}

public function number_rows(){

return $this->info['num_rows'];

//return $someData;

}

public function last_query(){

return $info['last_query'];

}

public function insert_id(){

return $info['insert_id'];

}

static private function connection(){

echo "creating connection ";

return self::$link;

}

static private function __where($info, $type = 'AND'){

self::$where = $where;

}

public function where($field, $equal = null){

return $this;

}

public function and_where($field, $equal = null){

return $this->where($field, $equal);

}

public function or_where($field, $equal = null){

return $this;

}

public function limit($limit){

self::$limit = 'LIMIT '.$limit;

return $this;

}

public function order_by($by, $order_type = 'DESC'){

return $this;

}

public function query($qry, $return = false){

self::set('last_query', $qry);

return true;

}

public function get($table, $select = '*'){

// return $data;

return self::$dummyQueryResponse;

}

public function insert($table, $data){

return true;

}

public function update($table, $info){

return true;

}

public function delete($table){

return true;

}

};

?>

The first part should make call to every public function in second part.

as a hint- add the calls tp the member function 1 at a time. Each member function will generate error which have to be fixed.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!