MySQL Forums
Forum List  »  PHP

Re: PHP OO query problem --Couldn't fetch my_mysqli
Posted by: Roy Leroux
Date: December 05, 2013 11:09AM

I got it. Thanks for the help!
Here is the output:
Connect succeeded: localhost via TCP/IP
Query succeeded: classes, items, packedins,
close succeeded

Here is the code
echo "
<html><head><title>Database Test</title></head><body>";
$DB=new my_mysqli('travel');
$DB->do_query('show tables');

class my_mysqli extends mysqli {
static $link;
public function __construct($database){
$link = mysqli_connect($server,$username,$userpassword,$database);
if (!$link) die('Connect Error ('.mysqli_connect_errno().')'.mysqli_connect_error());
else echo 'Connect succeeded: ' . mysqli_get_host_info($link) . "<br />\n";
self::$link=$link; //HERE!
}//end __construct

public function do_query($query){
if (!$result){echo "do_query,$query, error=" . $this->error . "<br />";}
else {
echo "Query succeeded: ";
while ($row = $result->fetch_assoc()) {
foreach($row as $value){echo "$value, ";}
}//end while
echo "<br />\n";
}//end else
}//end do_query

public function do_close(){
if (!self::$link->close()) echo "Close failed<br />\n"; else echo "Close succeeded<br />\n";
}//end do_close
}//end class my_mysqli

Edited 2 time(s). Last edit at 12/05/2013 11:13AM by Roy Leroux.

Options: ReplyQuote

Written By
Re: PHP OO query problem --Couldn't fetch my_mysqli
December 05, 2013 11:09AM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.