[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 281
  • Last Modified:

Extended MySQLi class

Hi! I'm looking for a good, clean, easy to use mysqli wrapper class that will return associative arrays, etc. Unfortunately, I don't think I have the time to write one myself. Is there anything like that, that you know of, available?
0
Julian Matz
Asked:
Julian Matz
  • 2
  • 2
1 Solution
 
Ray PaseurCommented:
0
 
Julian MatzAuthor Commented:
Yes, but I'd like to be able to do something like this:

$sql = new mysqli_extended();
$result = $sql->query( "SELECT * FROM table" );

print_r( $result );

-- which would print out an associative array for me. In other words, the class would be able to distinguish between SELECT and INSERT or UPDATE queries. Does that make sense?

0
 
Ray PaseurCommented:
I think the part about understanding the difference between SELECT, INSERT and UPDATE is fairly easy.  But the results set from a SELECT is not an associative array.  It's a resource that gives you access to a collection of rows.  Each row is an associative array.  The results set may contain zero, one or many rows.  

If you wanted to retrieve all of the rows at once, you could return them in a two-dimensional array with something like this (but that is kind of awkward in my opinion):

$allrows = array();
while ($row = mysqli_fetch_assoc($resource))
{
    $allrows[] = $row;
}
0
 
Bryan_HeathCommented:
Might want to look at:
http://adodb.sourceforge.net/

See:
http://phplens.com/adodb/tutorial.select.html

If you really want to get hard core you could also use Doctrine:
http://www.doctrine-project.org/
0
 
Julian MatzAuthor Commented:
Thanks, Ray, I know that. It's just I was wondering if there was a class out there somewhere that would do some of the "heavy lifting" for me - e.g. return a two-dimensional array in the case of a SELECT query, and maybe just TRUE or FALSE in the case of DELETE, and maybe (int)$mysqli->affected_rows for an UPDATE or INSERT, etc.

Thanks, Bryan, will have a look at those.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now