Go Back   HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials > Linux Forums > Programming/Scripts

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
Reply
 
Thread Tools Display Modes
  #1  
Old 26th July 2007, 19:17
Juddling Juddling is offline
Junior Member
 
Join Date: Jul 2007
Posts: 19
Thanks: 1
Thanked 0 Times in 0 Posts
Default PHP number of queries executed

Is there a way of counting the number of queries executed I have seen it on other websites.

Changing all my mysql_query() functions to a "home-made" function is out of the question, I have thousands of uses of the function.

Is this possible?

Thanks
Reply With Quote
Sponsored Links
  #2  
Old 28th July 2007, 10:06
till till is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 35,672
Thanks: 819
Thanked 5,317 Times in 4,170 Posts
Default

Have a look at the function:

mysql_affected_rows()

to get the number of records affected by your query.
__________________
Till Brehm
--
Get ISPConfig support and the ISPConfig 3 manual from ispconfig.org.
Reply With Quote
  #3  
Old 28th July 2007, 10:37
Juddling Juddling is offline
Junior Member
 
Join Date: Jul 2007
Posts: 19
Thanks: 1
Thanked 0 Times in 0 Posts
Default mysql_affected_rows()

That's only for your last query executed and it still doesn't do what i'm looking for sorry mate.
Reply With Quote
  #4  
Old 28th July 2007, 10:43
till till is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 35,672
Thanks: 819
Thanked 5,317 Times in 4,170 Posts
Default

The function must be called after each execution of the mysql_query command. There is no other solution, thats the way it is done in PHP and other sites are doing it this way.
__________________
Till Brehm
--
Get ISPConfig support and the ISPConfig 3 manual from ispconfig.org.
Reply With Quote
  #5  
Old 4th August 2007, 09:39
blu3ness blu3ness is offline
Junior Member
 
Join Date: Aug 2007
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
Default

We do it by writing a wrapper class to wrap all of our MYSQL query functions.
It makes it very ez to tally these kind of statistics if it is ever required.

So yes, I would suggest writing your own wrapper functions for those mysql queries, they will come in very handy later on
Reply With Quote
  #6  
Old 17th August 2007, 21:09
smeguru smeguru is offline
Junior Member
 
Join Date: Nov 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Wrapper example

Would you mind sharing the code for your wrapper as this is something I would like to do on a new project myself.


Quote:
Originally Posted by blu3ness
We do it by writing a wrapper class to wrap all of our MYSQL query functions.
It makes it very ez to tally these kind of statistics if it is ever required.

So yes, I would suggest writing your own wrapper functions for those mysql queries, they will come in very handy later on
Reply With Quote
  #7  
Old 17th August 2007, 22:16
blu3ness blu3ness is offline
Junior Member
 
Join Date: Aug 2007
Posts: 7
Thanks: 0
Thanked 0 Times in 0 Posts
 
Default

This is a part of the wrapper. Just to give you an example do not toe xpect it to be in working condition..

PHP Code:
class MysqlDataBase implements DataBase
{
    
/* === Constructor / Destructor === */
    
function __construct $host$username$passwd )
    {
    
$this->link null;
    if( !( 
$this->link mysql_pconnect$host$username$passwd ) ) )
        
// Connection could not be opened.
        
throw new DataBaseExceptionmysql_error(), ERR_DB );
    }

    function 
__destruct()
    {
    if( 
$this->link )
        
mysql_close$this->link );
    }

    
// isConnected:
    // Returns true if the database is currently connected.
    
public function isConnected()
    {
    return 
mysql_ping$this->link );
    }

    
/* === DataBase === */

    // useDataBase:
    // Selects 'db' for use in proceeding queries
    
public function useDataBase$db )
    {
    if( !
mysql_select_db$db$this->link ) )
        throw new 
DataBaseExceptionmysql_error(), ERR_DB );
    }

    
/* === Transaction Stuff === */

    // commitTransaction:
    // Commits all of the queries made since startTransaction was
    // called.
 
    // startTransaction:
    // Start a transaction.
 

    // rollBackTransaction:
    // Cancels the current transaction.
 
    // setSavePoint:
    // Creates a new save point and returns an object of type SavePoint
  

    // releaseSavePoint:
    // Releases the given save point
 
    // rollBackToSavePoint:
    // Roll's back the transaction to the given save point
 
    /* === Run Query === */

    // query:
    // Run a query then return an object of type QueryResult
    
public function query$query )
    {
    
$this->count++;

    if( 
$this->do_print )
        print 
$query."<br><br>";

    if( 
$result mysql_query$query$this->link ) )
    {
        
// Query suceeded create a new wrapper class from $result
        
return new MysqlQueryResult$result );
    }else{
        throw new 
DataBaseExceptionmysql_error()."<br><br>Query: $query"
                     
ERR_DB );
    }
    }

    
// getAffectedRowCount:
    // Returns the number of rows affected by the last operation.
    
public function getAffectedRowCount()
    {
    return 
mysql_affected_rows$this->link );
    }

    
// getLastAutoID:
    // Returns the last generated auto_increment id
    
public function getLastAutoID()
    {
    return 
mysql_insert_id$this->link );
    }

    
/* === Error === */

    // getLastError:
    // Returns a string containing the last error that occured.
    
public function getLastError()
    {
    return 
mysql_error($this->link);
    }

    
// getLastErrorNum:
    // Returns a string containing the last error number that occured.
    
public function getLastErrorNum()
    {
    return 
mysql_errno($this->link);
    }

    
/* === Info === */
    
    // getQueryCount:
    // Returns the total number of queries made to the database
    
public function getQueryCount()
    {
    return 
$this->count;
    }

    
// setPrintQueries:
    // Sets wether or not queries should be printed.
    
public function setPrintQueries$do_print )
    {
    
$this->do_print $do_print;
    }



    
/* === Private Data === */

    
private static $save_point_id;

    
// Database Link
    
private $link;
    private 
$do_print;
    private 
$count;
}




?> 
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Freebsd 6.1 support misterm Installation/Configuration 10 9th April 2009 09:29
php eating cpu shajazzi Server Operation 15 15th August 2007 01:19
Slightly Confused (DNS & Server Help) JohnnyBGoode Installation/Configuration 26 14th August 2007 09:54
Apache2 Freezes celtic Server Operation 31 28th May 2007 17:18


All times are GMT +2. The time now is 18:36.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.