Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #9213 > unrolled thread

determine a mysqli_result object

Started byScott Johnson <noonehome@chalupasworld.com>
First post2013-04-27 16:11 -0700
Last post2013-04-27 16:18 -0700
Articles 2 — 1 participant

Back to article view | Back to comp.lang.php


Contents

  determine a mysqli_result object Scott Johnson <noonehome@chalupasworld.com> - 2013-04-27 16:11 -0700
    Re: determine a mysqli_result object Scott Johnson <noonehome@chalupasworld.com> - 2013-04-27 16:18 -0700

#9213 — determine a mysqli_result object

FromScott Johnson <noonehome@chalupasworld.com>
Date2013-04-27 16:11 -0700
Subjectdetermine a mysqli_result object
Message-ID<klhlph$vgi$1@dont-email.me>
I have a class that I am converting from mysql to mysqli in PHP 5.2.x

The problem I ran into is this.

Previously I could check the mysql_query if it return a resource by using:

is_resource($resource)

and could parse the resource using mysql_fetch_assoc or similar

and if it was an insert, update, etc.. it would not return a resource 
and I would just return a true and carry on.

Now with mysqli it return a mysql_result object.

How do I check for this so I know whether to parse or return

Thanks

Here is a nutshell of what was using for mysql

// Already connected to mysqli

public function query($query){
  $resource = $this->connection->query($query);

  if($resource) {

   if(is_resource($resource)) { // parse

    $data = array();

    $idx = 0;

    while($result = $this->connection->fetch_assoc()) {

     $data[$idx] = $result;
     // Object assembly

    }
   } else { // return

    // update, insert, etc..
    return true;

   }
  } else {
   // error
  }
}

Scotty

[toc] | [next] | [standalone]


#9214

FromScott Johnson <noonehome@chalupasworld.com>
Date2013-04-27 16:18 -0700
Message-ID<klhm5j$ss$1@dont-email.me>
In reply to#9213
On 4/27/2013 4:11 PM, Scott Johnson wrote:
> I have a class that I am converting from mysql to mysqli in PHP 5.2.x
>
> The problem I ran into is this.
>
> Previously I could check the mysql_query if it return a resource by using:
>
> is_resource($resource)
>
> and could parse the resource using mysql_fetch_assoc or similar
>
> and if it was an insert, update, etc.. it would not return a resource
> and I would just return a true and carry on.
>
> Now with mysqli it return a mysql_result object.
>
> How do I check for this so I know whether to parse or return
>
> Thanks
>
> Here is a nutshell of what was using for mysql
>
> // Already connected to mysqli
>
> public function query($query){
>   $resource = $this->connection->query($query);
>
>   if($resource) {
>
>    if(is_resource($resource)) { // parse
>
>     $data = array();
>
>     $idx = 0;
>
>     while($result = $this->connection->fetch_assoc()) {
>
>      $data[$idx] = $result;
>      // Object assembly
>
>     }
>    } else { // return
>
>     // update, insert, etc..
>     return true;
>
>    }
>   } else {
>    // error
>   }
> }
>
> Scotty


Crap figured it out.  Was binging for the wrong answer.

if($result_obj) {
	if($result_obj instanceof mysqli_result) {
		echo 'good';
		$data = array();
		$idx = 0;
		while($result = $result_obj->fetch_assoc()) {
			$data[$idx] = $result;
			$idx++;
		}
		print_r($data);
	} else {
		return true;
	}
}

Scotty

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.php


csiph-web