Extending the mysqli class

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Daz

    Extending the mysqli class

    Hi everyone.

    I am trying to create an extension of the mysqli class within PHP, and
    I am finding it quite difficult. I am fairly new to PHP classes, and
    decided to give them a go. Here's what I have to far:

    <?php
    class sql_db extends mysqli
    {
    var $connection = false;
    function sql_db($usernam e, $password, $database="",
    $server="localh ost")
    {
    $this->connection = new mysqli($server, $username,
    $password, $database);
    if (mysqli_connect _errno()) {
    printf("Connect failed: %s\n",
    mysqli_connect_ error());
    exit();
    }
    return = $this->connection;
    }
    }
    ?>

    All I am trying to achieve for now is for a simple error to be printed
    if the connection to the database fails. Rather than have error
    checking for each within each PHP file, I would just like to have it
    all done systematically. I would also like to add a few of my own
    methods, such as having the object pass back a PHP array, rather than
    a MySQL array. I know I can do this with a separate function, but
    really I am doing this for the learning experience more than anything.

    At the present time, this works:

    $db =& new sql_db("myUsern ame", "myPass", "someDB");

    But as soon as I try to query a table, like so:

    $res = $db->query("SELEC T * FROM `some_table`;") ;

    I get:

    Warning: mysqli::query() : Couldn't fetch sql_db in - on line 21

    Evidently I am doing something wrong, and I would really appreciate
    any pointers. I suspect that I can't actually do what I want to do,
    although I can't see why not. In any case, I am sure it's possible,
    but I am going about it completely wrong.

    Thanks in advance.

    Daz.

  • Jerry Stuckle

    #2
    Re: Extending the mysqli class

    Daz wrote:
    Hi everyone.
    >
    I am trying to create an extension of the mysqli class within PHP, and
    I am finding it quite difficult. I am fairly new to PHP classes, and
    decided to give them a go. Here's what I have to far:
    >
    <?php
    class sql_db extends mysqli
    {
    var $connection = false;
    function sql_db($usernam e, $password, $database="",
    $server="localh ost")
    {
    $this->connection = new mysqli($server, $username,
    $password, $database);
    if (mysqli_connect _errno()) {
    printf("Connect failed: %s\n",
    mysqli_connect_ error());
    exit();
    }
    return = $this->connection;
    }
    }
    ?>
    >
    All I am trying to achieve for now is for a simple error to be printed
    if the connection to the database fails. Rather than have error
    checking for each within each PHP file, I would just like to have it
    all done systematically. I would also like to add a few of my own
    methods, such as having the object pass back a PHP array, rather than
    a MySQL array. I know I can do this with a separate function, but
    really I am doing this for the learning experience more than anything.
    >
    At the present time, this works:
    >
    $db =& new sql_db("myUsern ame", "myPass", "someDB");
    >
    But as soon as I try to query a table, like so:
    >
    $res = $db->query("SELEC T * FROM `some_table`;") ;
    >
    I get:
    >
    Warning: mysqli::query() : Couldn't fetch sql_db in - on line 21
    >
    Evidently I am doing something wrong, and I would really appreciate
    any pointers. I suspect that I can't actually do what I want to do,
    although I can't see why not. In any case, I am sure it's possible,
    but I am going about it completely wrong.
    >
    Thanks in advance.
    >
    Daz.
    >
    Daz,

    If you're going to extend a class, you don't use:

    $this->connection = new mysqli($server, $username,
    $password, $database);

    You already have an instance of mysqli via inheritance; this would be
    creating another one.

    Rather, you should be using

    parent::mysqli( $server, $username, $password, $database);

    (Assuming PHP4 from your previous post).

    You also don't need to keep the $connection - mysqli will maintain that
    info..

    --
    =============== ===
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    jstucklex@attgl obal.net
    =============== ===

    Comment

    • Daz

      #3
      Re: Extending the mysqli class

      On Feb 25, 3:41 pm, "Daz" <cutenfu...@gma il.comwrote:
      Hi everyone.
      >
      I am trying to create an extension of the mysqli class within PHP, and
      I am finding it quite difficult. I am fairly new to PHP classes, and
      decided to give them a go. Here's what I have to far:
      >
      <?php
      class sql_db extends mysqli
      {
      var $connection = false;
      function sql_db($usernam e, $password, $database="",
      $server="localh ost")
      {
      $this->connection = new mysqli($server, $username,
      $password, $database);
      if (mysqli_connect _errno()) {
      printf("Connect failed: %s\n",
      mysqli_connect_ error());
      exit();
      }
      return = $this->connection;
      }
      }
      ?>
      >
      All I am trying to achieve for now is for a simple error to be printed
      if the connection to the database fails. Rather than have error
      checking for each within each PHP file, I would just like to have it
      all done systematically. I would also like to add a few of my own
      methods, such as having the object pass back a PHP array, rather than
      a MySQL array. I know I can do this with a separate function, but
      really I am doing this for the learning experience more than anything.
      >
      At the present time, this works:
      >
      $db =& new sql_db("myUsern ame", "myPass", "someDB");
      >
      But as soon as I try to query a table, like so:
      >
      $res = $db->query("SELEC T * FROM `some_table`;") ;
      >
      I get:
      >
      Warning: mysqli::query() : Couldn't fetch sql_db in - on line 21
      >
      Evidently I am doing something wrong, and I would really appreciate
      any pointers. I suspect that I can't actually do what I want to do,
      although I can't see why not. In any case, I am sure it's possible,
      but I am going about it completely wrong.
      >
      Thanks in advance.
      >
      Daz.

      OK, I've done some more thinking, and I think that what I am trying to
      do, would involve overriding the constructor of the mysqli class,
      which I guess wouldn't be wise, and might not even be possible.

      Is there any way to override the contructor and find out what the
      constructor code is? I guess that it wouldn't be a PHP class as such,
      but more of a hybrid, but I am uncertain.

      I can see that what I am doing is correct for adding extra functions,
      but I would appreciate it if anyone can help me figure out the best
      way to do some error checking when the connection is opened.

      I would also appreciate any input on overriding the default methods,
      i.e whether it's possible or not, or whether it's ill advised, or if I
      can actually use the original constructor and carefully modify it.

      I think the initial error checking might require an external function
      which instantiates the class, and does the checking, then returns the
      mysqli object if all went well, or returns false if it didn't.

      Comment

      • Daz

        #4
        Re: Extending the mysqli class

        On Feb 25, 3:55 pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
        Daz wrote:
        Hi everyone.
        >
        I am trying to create an extension of the mysqli class within PHP, and
        I am finding it quite difficult. I am fairly new to PHP classes, and
        decided to give them a go. Here's what I have to far:
        >
        <?php
        class sql_db extends mysqli
        {
        var $connection = false;
        function sql_db($usernam e, $password, $database="",
        $server="localh ost")
        {
        $this->connection = new mysqli($server, $username,
        $password, $database);
        if (mysqli_connect _errno()) {
        printf("Connect failed: %s\n",
        mysqli_connect_ error());
        exit();
        }
        return = $this->connection;
        }
        }
        ?>
        >
        All I am trying to achieve for now is for a simple error to be printed
        if the connection to the database fails. Rather than have error
        checking for each within each PHP file, I would just like to have it
        all done systematically. I would also like to add a few of my own
        methods, such as having the object pass back a PHP array, rather than
        a MySQL array. I know I can do this with a separate function, but
        really I am doing this for the learning experience more than anything.
        >
        At the present time, this works:
        >
        $db =& new sql_db("myUsern ame", "myPass", "someDB");
        >
        But as soon as I try to query a table, like so:
        >
        $res = $db->query("SELEC T * FROM `some_table`;") ;
        >
        I get:
        >
        Warning: mysqli::query() : Couldn't fetch sql_db in - on line 21
        >
        Evidently I am doing something wrong, and I would really appreciate
        any pointers. I suspect that I can't actually do what I want to do,
        although I can't see why not. In any case, I am sure it's possible,
        but I am going about it completely wrong.
        >
        Thanks in advance.
        >
        Daz.
        >
        Daz,
        >
        If you're going to extend a class, you don't use:
        >
        $this->connection = new mysqli($server, $username,
        $password, $database);
        >
        You already have an instance of mysqli via inheritance; this would be
        creating another one.
        >
        Rather, you should be using
        >
        parent::mysqli( $server, $username, $password, $database);
        >
        (Assuming PHP4 from your previous post).
        >
        You also don't need to keep the $connection - mysqli will maintain that
        info..
        >
        --
        =============== ===
        Remove the "x" from my email address
        Jerry Stuckle
        JDS Computer Training Corp.
        jstuck...@attgl obal.net
        =============== ===

        Thanks for that Jerry. That gives me something to go on. I am using
        PHP5, as I believe PHP4 doesn't support the mysqli object (but I am
        most likely wrong).

        Thanks again for your assistance.

        Daz.

        Comment

        • Jerry Stuckle

          #5
          Re: Extending the mysqli class

          Daz wrote:
          On Feb 25, 3:55 pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
          >Daz wrote:
          >>Hi everyone.
          >>I am trying to create an extension of the mysqli class within PHP, and
          >>I am finding it quite difficult. I am fairly new to PHP classes, and
          >>decided to give them a go. Here's what I have to far:
          >> <?php
          >> class sql_db extends mysqli
          >> {
          >> var $connection = false;
          >> function sql_db($usernam e, $password, $database="",
          >>$server="loca lhost")
          >> {
          >> $this->connection = new mysqli($server, $username,
          >>$password, $database);
          >> if (mysqli_connect _errno()) {
          >> printf("Connect failed: %s\n",
          >>mysqli_connec t_error());
          >> exit();
          >> }
          >> return = $this->connection;
          >> }
          >> }
          >> ?>
          >>All I am trying to achieve for now is for a simple error to be printed
          >>if the connection to the database fails. Rather than have error
          >>checking for each within each PHP file, I would just like to have it
          >>all done systematically. I would also like to add a few of my own
          >>methods, such as having the object pass back a PHP array, rather than
          >>a MySQL array. I know I can do this with a separate function, but
          >>really I am doing this for the learning experience more than anything.
          >>At the present time, this works:
          >> $db =& new sql_db("myUsern ame", "myPass", "someDB");
          >>But as soon as I try to query a table, like so:
          >> $res = $db->query("SELEC T * FROM `some_table`;") ;
          >>I get:
          >> Warning: mysqli::query() : Couldn't fetch sql_db in - on line 21
          >>Evidently I am doing something wrong, and I would really appreciate
          >>any pointers. I suspect that I can't actually do what I want to do,
          >>although I can't see why not. In any case, I am sure it's possible,
          >>but I am going about it completely wrong.
          >>Thanks in advance.
          >>Daz.
          >Daz,
          >>
          >If you're going to extend a class, you don't use:
          >>
          > $this->connection = new mysqli($server, $username,
          >$password, $database);
          >>
          >You already have an instance of mysqli via inheritance; this would be
          >creating another one.
          >>
          >Rather, you should be using
          >>
          > parent::mysqli( $server, $username, $password, $database);
          >>
          >(Assuming PHP4 from your previous post).
          >>
          >You also don't need to keep the $connection - mysqli will maintain that
          >info..
          >>
          >--
          >============== ====
          >Remove the "x" from my email address
          >Jerry Stuckle
          >JDS Computer Training Corp.
          >jstuck...@attg lobal.net
          >============== ====
          >
          >
          Thanks for that Jerry. That gives me something to go on. I am using
          PHP5, as I believe PHP4 doesn't support the mysqli object (but I am
          most likely wrong).
          >
          Thanks again for your assistance.
          >
          Daz.
          >
          Daz,

          Actually, PHP4 does support the mysqli object, also.

          But in PHP5 your constructors are named __construct, not the class name.
          So you need to change the constructor name in your class, and call

          parent::constru ct(...)

          instead.


          --
          =============== ===
          Remove the "x" from my email address
          Jerry Stuckle
          JDS Computer Training Corp.
          jstucklex@attgl obal.net
          =============== ===

          Comment

          • Jerry Stuckle

            #6
            Re: Extending the mysqli class

            Daz wrote:
            On Feb 25, 3:41 pm, "Daz" <cutenfu...@gma il.comwrote:
            >Hi everyone.
            >>
            >I am trying to create an extension of the mysqli class within PHP, and
            >I am finding it quite difficult. I am fairly new to PHP classes, and
            >decided to give them a go. Here's what I have to far:
            >>
            > <?php
            > class sql_db extends mysqli
            > {
            > var $connection = false;
            > function sql_db($usernam e, $password, $database="",
            >$server="local host")
            > {
            > $this->connection = new mysqli($server, $username,
            >$password, $database);
            > if (mysqli_connect _errno()) {
            > printf("Connect failed: %s\n",
            >mysqli_connect _error());
            > exit();
            > }
            > return = $this->connection;
            > }
            > }
            > ?>
            >>
            >All I am trying to achieve for now is for a simple error to be printed
            >if the connection to the database fails. Rather than have error
            >checking for each within each PHP file, I would just like to have it
            >all done systematically. I would also like to add a few of my own
            >methods, such as having the object pass back a PHP array, rather than
            >a MySQL array. I know I can do this with a separate function, but
            >really I am doing this for the learning experience more than anything.
            >>
            >At the present time, this works:
            >>
            > $db =& new sql_db("myUsern ame", "myPass", "someDB");
            >>
            >But as soon as I try to query a table, like so:
            >>
            > $res = $db->query("SELEC T * FROM `some_table`;") ;
            >>
            >I get:
            >>
            > Warning: mysqli::query() : Couldn't fetch sql_db in - on line 21
            >>
            >Evidently I am doing something wrong, and I would really appreciate
            >any pointers. I suspect that I can't actually do what I want to do,
            >although I can't see why not. In any case, I am sure it's possible,
            >but I am going about it completely wrong.
            >>
            >Thanks in advance.
            >>
            >Daz.
            >
            >
            OK, I've done some more thinking, and I think that what I am trying to
            do, would involve overriding the constructor of the mysqli class,
            which I guess wouldn't be wise, and might not even be possible.
            >
            Is there any way to override the contructor and find out what the
            constructor code is? I guess that it wouldn't be a PHP class as such,
            but more of a hybrid, but I am uncertain.
            >
            I can see that what I am doing is correct for adding extra functions,
            but I would appreciate it if anyone can help me figure out the best
            way to do some error checking when the connection is opened.
            >
            I would also appreciate any input on overriding the default methods,
            i.e whether it's possible or not, or whether it's ill advised, or if I
            can actually use the original constructor and carefully modify it.
            >
            I think the initial error checking might require an external function
            which instantiates the class, and does the checking, then returns the
            mysqli object if all went well, or returns false if it didn't.
            >
            Daz,

            Overriding the constructor is quite common. But you need to ensure you
            also call the parent class constructor.

            As to seeing the code - it's like anything else in PHP. If it's a PHP
            file, you can see the code. If, like with mysqli, it's a compiled
            extension, you need to look at the source code for the extension.

            If you want some error checking when you open the connection, see if the
            connection is open after calling the mysqli constructor (see if
            mysqli_connect_ error() is non-zero).

            You don't need an external function - you just need to check for errors.
            And if you don't want to keep checking the responses, check you
            exception handling.

            --
            =============== ===
            Remove the "x" from my email address
            Jerry Stuckle
            JDS Computer Training Corp.
            jstucklex@attgl obal.net
            =============== ===

            Comment

            • Daz

              #7
              Re: Extending the mysqli class

              On Feb 25, 4:17 pm, Jerry Stuckle <jstuck...@attg lobal.netwrote:
              Daz wrote:
              On Feb 25, 3:41 pm, "Daz" <cutenfu...@gma il.comwrote:
              Hi everyone.
              >
              I am trying to create an extension of the mysqli class within PHP, and
              I am finding it quite difficult. I am fairly new to PHP classes, and
              decided to give them a go. Here's what I have to far:
              >
              <?php
              class sql_db extends mysqli
              {
              var $connection = false;
              function sql_db($usernam e, $password, $database="",
              $server="localh ost")
              {
              $this->connection = new mysqli($server, $username,
              $password, $database);
              if (mysqli_connect _errno()) {
              printf("Connect failed: %s\n",
              mysqli_connect_ error());
              exit();
              }
              return = $this->connection;
              }
              }
              ?>
              >
              All I am trying to achieve for now is for a simple error to be printed
              if the connection to the database fails. Rather than have error
              checking for each within each PHP file, I would just like to have it
              all done systematically. I would also like to add a few of my own
              methods, such as having the object pass back a PHP array, rather than
              a MySQL array. I know I can do this with a separate function, but
              really I am doing this for the learning experience more than anything.
              >
              At the present time, this works:
              >
              $db =& new sql_db("myUsern ame", "myPass", "someDB");
              >
              But as soon as I try to query a table, like so:
              >
              $res = $db->query("SELEC T * FROM `some_table`;") ;
              >
              I get:
              >
              Warning: mysqli::query() : Couldn't fetch sql_db in - on line 21
              >
              Evidently I am doing something wrong, and I would really appreciate
              any pointers. I suspect that I can't actually do what I want to do,
              although I can't see why not. In any case, I am sure it's possible,
              but I am going about it completely wrong.
              >
              Thanks in advance.
              >
              Daz.
              >
              OK, I've done some more thinking, and I think that what I am trying to
              do, would involve overriding the constructor of the mysqli class,
              which I guess wouldn't be wise, and might not even be possible.
              >
              Is there any way to override the contructor and find out what the
              constructor code is? I guess that it wouldn't be a PHP class as such,
              but more of a hybrid, but I am uncertain.
              >
              I can see that what I am doing is correct for adding extra functions,
              but I would appreciate it if anyone can help me figure out the best
              way to do some error checking when the connection is opened.
              >
              I would also appreciate any input on overriding the default methods,
              i.e whether it's possible or not, or whether it's ill advised, or if I
              can actually use the original constructor and carefully modify it.
              >
              I think the initial error checking might require an external function
              which instantiates the class, and does the checking, then returns the
              mysqli object if all went well, or returns false if it didn't.
              >
              Daz,
              >
              Overriding the constructor is quite common. But you need to ensure you
              also call the parent class constructor.
              >
              As to seeing the code - it's like anything else in PHP. If it's a PHP
              file, you can see the code. If, like with mysqli, it's a compiled
              extension, you need to look at the source code for the extension.
              >
              If you want some error checking when you open the connection, see if the
              connection is open after calling the mysqli constructor (see if
              mysqli_connect_ error() is non-zero).
              >
              You don't need an external function - you just need to check for errors.
              And if you don't want to keep checking the responses, check you
              exception handling.
              >
              --
              =============== ===
              Remove the "x" from my email address
              Jerry Stuckle
              JDS Computer Training Corp.
              jstuck...@attgl obal.net
              =============== ===

              Thanks for that Jerry. You're a star! :)

              Comment

              • peter

                #8
                Re: Extending the mysqli class

                Actually, PHP4 does support the mysqli object, also.
                >
                But in PHP5 your constructors are named __construct, not the class name.
                So you need to change the constructor name in your class, and call
                >
                parent::constru ct(...)
                Just a correction of Jerry's post. As of php 5 the __constructor method was
                made available BUT the old constructor name is still useable.

                The class you are actually using (mysqli) does in fact use a contructor
                called mysqli as the following code snippet will demonstrate if you run it:-

                <?php
                function output_methods( $obj)
                {
                $methods = get_class_metho ds($obj);
                foreach ($methods as $method)
                {
                echo "function $method()\n";
                }
                }

                output_methods( "mysqli");
                ?>



                Comment

                • peter

                  #9
                  Re: Extending the mysqli class

                  Actually, PHP4 does support the mysqli object, also.
                  >
                  But in PHP5 your constructors are named __construct, not the class name.
                  So you need to change the constructor name in your class, and call
                  >
                  parent::constru ct(...)
                  Also just thought of another clarification. If you do not declare a
                  constructor for a class that extends another class, the parent constructor
                  will be called. for example the following code snippet will output "parent
                  constructor and the input was THIS TEXT":-

                  <?php
                  class c1
                  {
                  function __construct($in put)
                  {
                  echo "parent constructor and the input was ".$input;
                  }
                  }
                  class c2 extends c1
                  {
                  }
                  $c = new c2('THIS TEXT');
                  ?>


                  Comment

                  • Daz

                    #10
                    Re: Extending the mysqli class

                    On Feb 25, 5:15 pm, "peter" <sub...@flexiwe bhost.comwrote:
                    Actually, PHP4 does support the mysqli object, also.
                    >
                    But in PHP5 your constructors are named __construct, not the class name.
                    So you need to change the constructor name in your class, and call
                    >
                    parent::constru ct(...)
                    >
                    Just a correction of Jerry's post. As of php 5 the __constructor method was
                    made available BUT the old constructor name is still useable.
                    >
                    The class you are actually using (mysqli) does in fact use a contructor
                    called mysqli as the following code snippet will demonstrate if you run it:-
                    >
                    <?php
                    function output_methods( $obj)
                    {
                    $methods = get_class_metho ds($obj);
                    foreach ($methods as $method)
                    {
                    echo "function $method()\n";
                    }
                    >
                    }
                    >
                    output_methods( "mysqli");
                    ?>

                    Excellent! Just what I needed :)

                    I am wondering why constructors are different in PHP5. Surely anyone
                    coding portable scripts, would just use the PHP4 constructor
                    technique, as there's no guarantee that the server it needs to run on
                    is running PHP5. Some people have no control over what version of PHP
                    is installed if they are simply paying for a basic hosting account.
                    Fortunately for me, I have the choice between 4 and 5, but others
                    won't necessarilly be quite so fortunate.

                    Thanks for your help Peter. That's sure going to save me digging
                    through source code and scratching my head to to point of baldness.

                    Best wishes.

                    Daz.

                    Comment

                    • Daz

                      #11
                      Re: Extending the mysqli class

                      On Feb 25, 5:15 pm, "peter" <sub...@flexiwe bhost.comwrote:
                      Actually, PHP4 does support the mysqli object, also.
                      >
                      But in PHP5 your constructors are named __construct, not the class name.
                      So you need to change the constructor name in your class, and call
                      >
                      parent::constru ct(...)
                      >
                      Just a correction of Jerry's post. As of php 5 the __constructor method was
                      made available BUT the old constructor name is still useable.
                      >
                      The class you are actually using (mysqli) does in fact use a contructor
                      called mysqli as the following code snippet will demonstrate if you run it:-
                      >
                      <?php
                      function output_methods( $obj)
                      {
                      $methods = get_class_metho ds($obj);
                      foreach ($methods as $method)
                      {
                      echo "function $method()\n";
                      }
                      >
                      }
                      >
                      output_methods( "mysqli");
                      ?>

                      I have just one more question. Seeing that you can print methods, how
                      would I print the code from a function?

                      Many thanks.

                      Daz.

                      Comment

                      • Jerry Stuckle

                        #12
                        Re: Extending the mysqli class

                        peter wrote:
                        >Actually, PHP4 does support the mysqli object, also.
                        >>
                        >But in PHP5 your constructors are named __construct, not the class name.
                        >So you need to change the constructor name in your class, and call
                        >>
                        > parent::constru ct(...)
                        >
                        Just a correction of Jerry's post. As of php 5 the __constructor method was
                        made available BUT the old constructor name is still useable.
                        >
                        That's true if there is no __constructor method. However, from what I
                        understand, the old classname constructor is going away. If you're on
                        PHP5, you should be using the new way.
                        The class you are actually using (mysqli) does in fact use a contructor
                        called mysqli as the following code snippet will demonstrate if you run it:-
                        >
                        <?php
                        function output_methods( $obj)
                        {
                        $methods = get_class_metho ds($obj);
                        foreach ($methods as $method)
                        {
                        echo "function $method()\n";
                        }
                        }
                        >
                        output_methods( "mysqli");
                        ?>
                        >
                        >
                        >

                        --
                        =============== ===
                        Remove the "x" from my email address
                        Jerry Stuckle
                        JDS Computer Training Corp.
                        jstucklex@attgl obal.net
                        =============== ===

                        Comment

                        • Jerry Stuckle

                          #13
                          Re: Extending the mysqli class

                          Daz wrote:
                          On Feb 25, 5:15 pm, "peter" <sub...@flexiwe bhost.comwrote:
                          >>Actually, PHP4 does support the mysqli object, also.
                          >>But in PHP5 your constructors are named __construct, not the class name.
                          >>So you need to change the constructor name in your class, and call
                          >> parent::constru ct(...)
                          >Just a correction of Jerry's post. As of php 5 the __constructor method was
                          >made available BUT the old constructor name is still useable.
                          >>
                          >The class you are actually using (mysqli) does in fact use a contructor
                          >called mysqli as the following code snippet will demonstrate if you run it:-
                          >>
                          ><?php
                          >function output_methods( $obj)
                          >{
                          > $methods = get_class_metho ds($obj);
                          > foreach ($methods as $method)
                          > {
                          > echo "function $method()\n";
                          > }
                          >>
                          >}
                          >>
                          >output_methods ("mysqli");
                          >?>
                          >
                          >
                          Excellent! Just what I needed :)
                          >
                          I am wondering why constructors are different in PHP5. Surely anyone
                          coding portable scripts, would just use the PHP4 constructor
                          technique, as there's no guarantee that the server it needs to run on
                          is running PHP5. Some people have no control over what version of PHP
                          is installed if they are simply paying for a basic hosting account.
                          Fortunately for me, I have the choice between 4 and 5, but others
                          won't necessarilly be quite so fortunate.
                          >
                          Thanks for your help Peter. That's sure going to save me digging
                          through source code and scratching my head to to point of baldness.
                          >
                          Best wishes.
                          >
                          Daz.
                          >
                          Daz,

                          It was changed because they're moving away from the old classname
                          constructor to just __constructor. New code on php5 should be using the
                          new method.

                          For compatibility with PHP4, just create your constructor as
                          __constructor. Then create a classname constructor and have it call
                          __constructor.

                          --
                          =============== ===
                          Remove the "x" from my email address
                          Jerry Stuckle
                          JDS Computer Training Corp.
                          jstucklex@attgl obal.net
                          =============== ===

                          Comment

                          • Michael Fesser

                            #14
                            Re: Extending the mysqli class

                            ..oO(Daz)
                            >I am wondering why constructors are different in PHP5. Surely anyone
                            >coding portable scripts, would just use the PHP4 constructor
                            >technique
                            I don't care about PHP 4 anymore. Personally I consider it dead.
                            >as there's no guarantee that the server it needs to run on
                            >is running PHP5.
                            My scripts make use of many of the new OOP features in PHP 5, so they
                            won't run at all on PHP 4.

                            Micha

                            Comment

                            • admin@fahost.com

                              #15
                              Re: Extending the mysqli class

                              I havejustone more question. Seeing that you can print methods, how
                              would I print the code from a function?
                              As far as I know you cannot print the code for a class method only
                              retrieve it's name.

                              (had to use google groups to post a reply as for some some reason my
                              news provider is not working properly)

                              Comment

                              Working...