Results 1 to 3 of 3

Thread: Returning Database Retrieved Values

  1. #1

    Thread Starter
    Member
    Join Date
    Dec 2004
    Posts
    49

    Question Returning Database Retrieved Values

    Hi,

    I have a function in my database management class. What i want it to perform is that when i query the database which returns a single value, the function can do it for me.

    For example:
    My query is "SELECT Username FROM Customer WHERE CustomerID = 1"

    This query will return a single value result.

    My current function is this:

    public function executeScalar($aQuery) {
    $this->dbResult = mysql_query($aQuery,$this->getDBConnection()) ;
    $this->dbDataRow = mysql_fetch_row($this->dbResult) ;
    $this->retrievedValue = $this->dbDataRow[0] ;
    return $this->retrievedValue ;
    }

    I have other functions such as:
    - connect() : This function connect to the database with the login information
    - close() : This function closes the connection to the database
    - getDBConnection() : This function returns the current database connection
    - isConnected() : This function returns boolean variable whether there is connectivity to the database.

    I hope someone can assist me with this. Besides this, I also need a function to perform commands such as UPDATE, DELETE and INSERT.

    The function would actually returns the number of rows affected in the query. Could someone please assist me in that function? This is because I've tried many ways and I could not derive at the solution.

    The function header is:
    public function executeNonQuery($aQuery) {
    //Returns an integer indicating the number of rows affected in this query
    }

    Thank you.
    ______________________________________

    Warmest Regards,

    Lex
    ______________________________________



    :|: Don't Mess With The Predator :|:

  2. #2
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256

    Re: Returning Database Retrieved Values

    int mysql_affected_rows([resource link_identifier])

    mysql_affected_rows() returns the number of rows affected by the last INSERT, UPDATE or DELETE query associated with link_identifier. If the link identifier isn't specified, the last link opened by mysql_connect() is assumed.
    So...

    PHP Code:
    public function executeNonQuery($aQuery) {
         
    $this->dbResult mysql_query($aQuery,$this->getDBConnection());

         
    // either store value or return:
         
    return mysql_affected_rows($this->getDBConnection());

    My evil laugh has a squeak in it.

    kristopherwilson.com

  3. #3
    Lively Member {yak}'s Avatar
    Join Date
    Aug 2005
    Posts
    119

    Re: Returning Database Retrieved Values

    Are you asking for help on all of the functions? Or just the one that shows the affected rows? Simply, for affected rows, you can use mysql_affected_rows()

    Good luck;
    {yak}

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width