Webmaster Blog

Webmaster Resources

Initial SQL Connection Slow

Currently the first time I am connecting to my SQL database the loading time is very long. After that the loading speed is normal.

I will post possible solutions to make the initial connection faster here:
- HostNameLookups defined at httpd.conf is ON, set it to off
- Add skip-name-resolve to your my.cnf so that your SQL database is sending out a reverse IP lookup (more info here: Dotscr.org

To make sure that SQL is running with “skip-name-resolve” execute the following code via SSH:
mysqladmin variables

Wordpress: Count SQL Queries

For a developer loading speed is a crucial factor, therefore it is necessary to check how many SQL queries are needed to build a page.

To do that in Wordpress add this code anywhere in your template and it will show the queries that are needed until that specific part. If you want to know how many queries are needed for loading the full page then put the code in the footer.php

<? php echo get_num_queries(); ?>

You are able to use it several times inside your template, so insert it anywhere as many times as required.That’s great for locating potential “troublemakers”

Source:Playworkplay.com

SQL: Select table entries with the same value

Let’s say you got a table with lots of entries that have the same value and you want to safe each entry in an array even if it’s a “duplicate”, you can do it with a simple SQL query:

 

$query = $db->query("SELECT * FROM $db->tablename where exists ( SELECT tablerow_name FROM $db->tablename) ") ;

 

I hope that helps a bit :)