using mysqli as an extended class

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mbaroz
Forum Commoner
Posts: 29
Joined: Sun Feb 05, 2006 10:10 am

using mysqli as an extended class

Post by mbaroz »

HI There
I want to start using mysqli method to connect to my db . so far i had a complete class to use with mysql functions.

I tried to wrap the mysqli object as a custom class that query , return the rows as an array and so on.. but couldnt get a working one.

I need a class that use mysqli functions to connect, query , return rows array , and at the end closes the connection .

if anyone can help it would be Great
Thanks
Moshe
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

What have you tried thus far?
mbaroz
Forum Commoner
Posts: 29
Joined: Sun Feb 05, 2006 10:10 am

using mysqli as an extended class

Post by mbaroz »

HI
i tried to create a class:

Code: Select all

class db{
function db($host,$user,$pass,$dbname) {
$con=new mysqli(.....)
function GetRows() {
}
i dont know how to create the method of returning rows.

thats what i need help in .
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

If your class is going to contain an object of mysqli, then you will need to set a property of the class to an instance of the object so other methods can access it.

The basic concept is thus

Code: Select all

class foo
{
  var $my = null;
  function foo(..)
  {
    $this->my = new mysqli(..);
  }

  function bar(..)
  {
    return $this->my->someFunction();
  }
}
mbaroz
Forum Commoner
Posts: 29
Joined: Sun Feb 05, 2006 10:10 am

using mysqli as an extended class

Post by mbaroz »

Ok great ,
But what about the query / rows fetching method ? how it will work ?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

it's the same concept throughout.
Post Reply