Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- define("SELECT_FOUND_ROWS","SELECT FOUND_ROWS()");
- class foo_mysqli extends mysqli {
- private $host=HOSTNAME;
- private $user=USERNAME;
- private $pass=PASSWORD;
- private $db=DATABASE;
- public $querys;
- //SINGLETON
- public static function singleton() {
- if (!isset(self::$instance)){
- $c =__CLASS__;
- self::$instance=new $c;
- }
- return self::$instance;
- }
- //CONSTRUCTOR
- public function __construct() {
- parent::__construct($this->host,$this->user,$this->pass,$this->db);
- if (mysqli_connect_error()) {
- die('Connect Error 1(' . mysqli_connect_errno() . ') ' . mysqli_connect_error());
- }
- }
- public function query($query, $resultmode = MYSQLI_STORE_RESULT) {
- try{
- $this->querys++;
- return parent::query($query,$resultmode);
- }
- catch(Exception $e) {
- $message = $e->getMessage();
- $code = $e->getCode();
- $trace = $e->getTraceAsString();
- $this->error = "Error: $code :: $message - $trace";
- return false;
- }
- }
- //utf8 function try this function with cirylic charset
- public function utf8() {
- if (!parent::set_charset("utf8")) {
- printf("Error loading character set utf8: %s\n", parent::character_set_name() . parent::error);
- } else {
- printf("Current character set: %s\n", parent::character_set_name());
- }
- }
- }
- $db = new foo_mysqli();
- //why this is not working?
- function nums_results(){
- global $db;
- $num_results2 = array_pop($db->query(SELECT_FOUND_ROWS)->fetch_row());
- }
- //this works
- $num_results2 = array_pop($db->query(SELECT_FOUND_ROWS)->fetch_row());
- if($otro = $db->query("select SQL_CALC_FOUND_ROWS * from products order by id limit 0,20")){
- while ($obj = $otro->fetch_object()) {
- printf ("{%s, %s, %s, %s, %s, %d }; %s\n",
- $obj->ID,
- $obj->title,
- $obj->slug,
- $obj->price,
- $obj->content,
- $obj->cat,
- "<br>");
- }
- $otro->close();
- }
- echo " registers: " . nums_results();
- echo " registers: " . $nums_results2;
Add Comment
Please, Sign In to add comment