{"id":3785,"date":"2009-09-04T09:49:52","date_gmt":"2009-09-04T16:49:52","guid":{"rendered":"http:\/\/css-tricks.com\/?page_id=3785"},"modified":"2009-09-06T13:46:16","modified_gmt":"2009-09-06T20:46:16","slug":"get-all-time-number-of-mysql-queries","status":"publish","type":"page","link":"https:\/\/css-tricks.com\/snippets\/php\/get-all-time-number-of-mysql-queries\/","title":{"rendered":"Get All-Time Number of MySQL Queries"},"content":{"rendered":"
<?php\r\n       $handle=@mysql_connect(\"localhost\",\"root\",\"\");\r\n\r\n       if (!$handle)\r\n       {\r\n               die(\"No connection to database\");\r\n       }\r\n\r\n       echo 'Total number of all-time mysql-queries: '.getTotalNumberOfMySQLQuerys();\r\n\r\n\r\n       \/\/Returns integer-value of the total number of alltime mysql-calls that have been made\r\n       function getTotalNumberOfMySQLQuerys()\r\n       {\r\n               \/\/global mysql-status containing the number of querys has been renamed in newer versions of mysql\r\n               $mysqlVersion=getMysqlVersion();\r\n\r\n               \/\/contact helper-function to receive the mysql-version\r\n               if ($mysqlVersion()>=50002)\r\n               {\r\n                       $sql=\"SHOW GLOBAL STATUS LIKE 'Questions'\";\r\n               }\r\n               else\r\n               {\r\n                       $sql=\"SHOW STATUS LIKE 'Questions'\";\r\n               }\r\n\r\n               $result=@mysql_query( $sql );\r\n               $row=@mysql_fetch_array( $result );\r\n               return $row['Value'];\r\n       }\r\n\r\n       \/\/helper function is needed to detect the exact mysql-version\r\n       function getMysqlVersion()\r\n       {\r\n               $sql = 'SELECT VERSION() AS versionsinfo';\r\n               $result = @mysql_query('SELECT VERSION() AS versionsinfo');\r\n               $version = @mysql_result( $result, 0, \"versionsinfo\" );\r\n               $match = explode('.',$version);\r\n               return sprintf('%d%02d%02d',$match[0],$match[1],intval($match[2]));\r\n       }\r\n?><\/code><\/pre>\n

Because the name of the global mysql-status-variable containing the number of queries changed in later versions of mysql, a helper-function is needed to detect the exact version of mysql you’re running.<\/p>\n","protected":false},"excerpt":{"rendered":"

<?php $handle=@mysql_connect(“localhost”,”root”,””); if (!$handle) { die(“No connection to database”); } echo ‘Total number of all-time mysql-queries: ‘.getTotalNumberOfMySQLQuerys(); \/\/Returns integer-value of the total number of alltime mysql-calls that have been made function getTotalNumberOfMySQLQuerys() { \/\/global mysql-status containing the number of querys has been renamed in newer versions of mysql $mysqlVersion=getMysqlVersion(); \/\/contact helper-function to receive the mysql-version […]<\/p>\n","protected":false},"author":3,"featured_media":0,"parent":3233,"menu_order":0,"comment_status":"open","ping_status":"closed","template":"page-snippet.php","meta":{"_bbp_topic_count":0,"_bbp_reply_count":0,"_bbp_total_topic_count":0,"_bbp_total_reply_count":0,"_bbp_voice_count":0,"_bbp_anonymous_reply_count":0,"_bbp_topic_count_hidden":0,"_bbp_reply_count_hidden":0,"_bbp_forum_subforum_count":0,"sig_custom_text":"","sig_image_type":"featured-image","sig_custom_image":0,"sig_is_disabled":false,"inline_featured_image":false,"c2c_always_allow_admin_comments":false,"footnotes":""},"tags":[],"acf":[],"jetpack-related-posts":[{"id":4566,"url":"https:\/\/css-tricks.com\/snippets\/wordpress\/custom-loop-based-on-custom-fields\/","url_meta":{"origin":3785,"position":0},"title":"Custom Loop\/Query Based on Custom Fields","date":"October 30, 2009","format":false,"excerpt":"Last updated by Jason Witt. If you design or develop WordPress themes or plugins, there's a good chance that someday you'll need to make a query for custom meta fields. These are those completely custom key\/value pairs that you can attach to any post, page, or custom post type. WordPress\u2026","rel":"","context":"In "Article"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":169899,"url":"https:\/\/css-tricks.com\/video-screencasts\/133-figuring-responsive-images\/","url_meta":{"origin":3785,"position":1},"title":"#133: Figuring Out Responsive Images","date":"May 16, 2014","format":false,"excerpt":"I'm probably a bit rare in that I rather enjoyed trying to keep up on the responsive images thing. It's an interesting problem that bred lots of interesting solutions. The whole thing is starting to wrap up now though, now that the official solutions are: and friends with srcset and\u2026","rel":"","context":"With 49 comments","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3502,"url":"https:\/\/css-tricks.com\/snippets\/php\/mysql-backup-class\/","url_meta":{"origin":3785,"position":2},"title":"MySQL Backup Class","date":"August 22, 2009","format":false,"excerpt":"","rel":"","context":"In "Article"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3504,"url":"https:\/\/css-tricks.com\/snippets\/php\/mysql-restore-class\/","url_meta":{"origin":3785,"position":3},"title":"MySQL Restore Class","date":"August 22, 2009","format":false,"excerpt":"","rel":"","context":"In "Article"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":3510,"url":"https:\/\/css-tricks.com\/snippets\/php\/mysql-database-access-class\/","url_meta":{"origin":3785,"position":4},"title":"MySQL Database Access Class","date":"August 22, 2009","format":false,"excerpt":"","rel":"","context":"In "Article"","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":18377,"url":"https:\/\/css-tricks.com\/lodge\/v10\/058-custom-header-for-the-gallery-part-2-with-reverso-media-queries\/","url_meta":{"origin":3785,"position":5},"title":"#058: Custom Header for The Gallery, Part 2 (with Reverso Media Queries)","date":"September 19, 2012","format":false,"excerpt":"We have the basic gallery header in place, but it's missing the little blue people that Erica put in the original illustration. We had talked about it in advance, and decided it would be pretty cool if when the screen was resized, the people would stay put as the gallery\u2026","rel":"","context":"With 4 comments","img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"_links":{"self":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages\/3785"}],"collection":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/comments?post=3785"}],"version-history":[{"count":2,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages\/3785\/revisions"}],"predecessor-version":[{"id":3900,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages\/3785\/revisions\/3900"}],"up":[{"embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/pages\/3233"}],"wp:attachment":[{"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/media?parent=3785"}],"wp:term":[{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/css-tricks.com\/wp-json\/wp\/v2\/tags?post=3785"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}