<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss'><id>tag:blogger.com,1999:blog-781582386056490420</id><updated>2009-05-21T15:19:12.640-07:00</updated><title type='text'>MySQL Tips &amp; Tricks</title><subtitle type='html'>You can never know enough about MySQL, come here for frequent tips on the easy and tricky parts of database programming</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://mysqltips.co.uk/blog'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/posts/default'/><link rel='alternate' type='text/html' href='http://mysqltips.co.uk/index.php'/><link rel='next' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/posts/default?start-index=26&amp;max-results=25'/><author><name>zzapper</name><email>noreply@blogger.com</email></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>29</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-781582386056490420.post-7957045325372218212</id><published>2009-05-21T14:09:00.000-07:00</published><updated>2009-05-21T15:18:20.980-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql'/><category scheme='http://www.blogger.com/atom/ns#' term='case sensitivity'/><category scheme='http://www.blogger.com/atom/ns#' term='php'/><title type='text'>PHP, MySQL and Case Sensitivity of Field Names</title><content type='html'>MySQL is always case insensitive for field names (but not table names on *nix). &lt;br /&gt;&lt;br /&gt;Now here's the subtlety PHP will adopt what ever case you define in your query so if out of perversity you write your query , :-&lt;br /&gt;&lt;br /&gt;"select SuRnAmE from addresses"&lt;br /&gt;&lt;br /&gt;Then you will have to remember to use the same messy casing in PHP &lt;br /&gt;&lt;br /&gt;$surname=$row['SuRnAmE'];&lt;br /&gt;&lt;br /&gt;so better&lt;br /&gt;"select surname from tbl_addresses" &lt;br /&gt;&lt;br /&gt;$surname=$row['surname'];&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Play Safe always use lowercase!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/781582386056490420-7957045325372218212?l=mysqltips.co.uk%2Findex.php'/&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/7957045325372218212/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=781582386056490420&amp;postID=7957045325372218212' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/posts/default/7957045325372218212'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/posts/default/7957045325372218212'/><link rel='alternate' type='text/html' href='http://mysqltips.co.uk/2009/05/php-mysql-and-case-sensitivity-of-field.html' title='PHP, MySQL and Case Sensitivity of Field Names'/><author><name>zzapper</name><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='16255832060110662275'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-781582386056490420.post-6902468115787918685</id><published>2009-05-10T16:03:00.000-07:00</published><updated>2009-05-10T16:07:36.265-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Merging tables'/><title type='text'>MySQL Merging Two Identical Tables</title><content type='html'>The problem is that a straight * insertion will fail because of the primary keys which are likely to clash.&lt;br /&gt;&lt;br /&gt;The solution is specifically mention all the the other fields&lt;br /&gt;&lt;br /&gt;INSERT INTO table_1(col2, col3, col4) SELECT col2, col3, col4 FROM table_2;&lt;br /&gt;&lt;br /&gt;The primary key of table_1 should be auto_increment .&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/781582386056490420-6902468115787918685?l=mysqltips.co.uk%2Findex.php'/&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/6902468115787918685/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=781582386056490420&amp;postID=6902468115787918685' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/posts/default/6902468115787918685'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/posts/default/6902468115787918685'/><link rel='alternate' type='text/html' href='http://mysqltips.co.uk/2009/05/mysql-merging-two-identical-tables.html' title='MySQL Merging Two Identical Tables'/><author><name>zzapper</name><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='16255832060110662275'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-781582386056490420.post-6091873863039118084</id><published>2009-05-03T04:29:00.000-07:00</published><updated>2009-05-03T07:08:15.977-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='stackoverflow'/><category scheme='http://www.blogger.com/atom/ns#' term='multi-query'/><category scheme='http://www.blogger.com/atom/ns#' term='mysql'/><category scheme='http://www.blogger.com/atom/ns#' term='subquery'/><title type='text'>MySQL Subquery or Multiple Select Queries</title><content type='html'>Hi I have a table with one record per person and per item of clothing&lt;br /&gt;&lt;br /&gt;so&lt;br /&gt;&lt;br /&gt;peter, jumper,blue&lt;br /&gt;peter,trousers,green&lt;br /&gt;sue,dress,green&lt;br /&gt;peter,jumper,red&lt;br /&gt;gordon,jumper,green&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;I want to write a query to select all people with green jumpers but only if they have no other color jumper&lt;br /&gt;&lt;br /&gt;So in the above case it would ONLY select Gordon not greedy old Peter&lt;br /&gt;&lt;br /&gt;A solution provided is a sub select or multiple select query&lt;br /&gt;&lt;br /&gt;SELECT *&lt;br /&gt;FROM myTable AS t1&lt;br /&gt;WHERE t1.clothing = 'jumper' AND t1.color = 'green'&lt;br /&gt;AND NOT EXISTS(SELECT *&lt;br /&gt;FROM myTable AS t2&lt;br /&gt;WHERE t2.person = t1.person AND t2.clothing = 'jumper'&lt;br /&gt;AND t2.color &lt;&gt; 'green')&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/781582386056490420-6091873863039118084?l=mysqltips.co.uk%2Findex.php'/&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/6091873863039118084/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=781582386056490420&amp;postID=6091873863039118084' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/posts/default/6091873863039118084'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/posts/default/6091873863039118084'/><link rel='alternate' type='text/html' href='http://mysqltips.co.uk/2009/05/mysql-subquery-or-multiple-select.html' title='MySQL Subquery or Multiple Select Queries'/><author><name>zzapper</name><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='16255832060110662275'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-781582386056490420.post-8654542011025347959</id><published>2009-02-12T12:57:00.000-08:00</published><updated>2009-02-12T13:09:32.573-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql trap'/><category scheme='http://www.blogger.com/atom/ns#' term='alphanumeric sort'/><category scheme='http://www.blogger.com/atom/ns#' term='numeric sort'/><title type='text'>ordering a text field numerically (A MySQL trap)</title><content type='html'>If whatever reason you have numbers stored in a text field (char, varchar etc)then watch out if you try and do an order by as it will do the sort alphanumerically this means it will sort 1,10,2,3,4,5,6,7,8,9 when you would expect 1,2,3,4,5,6,7,8,9,10&lt;br /&gt;&lt;br /&gt;There is a work-around namely&lt;br /&gt;&lt;br /&gt;SELECT names FROM your_table ORDER BY names + 0 ASC&lt;br /&gt;&lt;br /&gt;where the +0 forces a numeric sort&lt;br /&gt;&lt;br /&gt;This trap occurs in quite a few programming languages and can be hard to spot&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/781582386056490420-8654542011025347959?l=mysqltips.co.uk%2Findex.php'/&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/8654542011025347959/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=781582386056490420&amp;postID=8654542011025347959' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/posts/default/8654542011025347959'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/posts/default/8654542011025347959'/><link rel='alternate' type='text/html' href='http://mysqltips.co.uk/2009/02/ordering-text-field-numerically-mysql.html' title='ordering a text field numerically (A MySQL trap)'/><author><name>zzapper</name><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='16255832060110662275'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-781582386056490420.post-7884869869225180077</id><published>2009-02-12T06:08:00.000-08:00</published><updated>2009-02-12T12:56:53.675-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='what to put in the code'/><category scheme='http://www.blogger.com/atom/ns#' term='mysql'/><category scheme='http://www.blogger.com/atom/ns#' term='php'/><category scheme='http://www.blogger.com/atom/ns#' term='query optimisation'/><title type='text'>How much intelligence in the MySQL Query how much in the Code?</title><content type='html'>SQL queries provide highly efficient access to parallel data (records). Very often you can get the exact data you require with your query and then all you have to do with your code is present it. Other times it simply isn't possible or isn't convenient to do it all in the SQL. In these cases typically you download the query results into an associative array, then you can further manipulate your data at leisure with all the power of PHP, Perl etc.&lt;br /&gt;&lt;br /&gt;What do I mean by convenient? well sometimes it might be possible to develop a complex query which drilled right down to the exact data but this might take time to perfect when you could have coded it much quicker.&lt;br /&gt;&lt;br /&gt;What's more I have found that over-complex queries are not very future proof, by that I mean a small change in the specification and they have to be rewritten. Further more they may not be very easy for other programmers to understand/maintain. &lt;br /&gt;&lt;br /&gt;So do the best query you can and then manipulate the data in your code.&lt;br /&gt;&lt;br /&gt;Truism: SQL can never be so flexible as a scripting/programming language such as PHP/Perl&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/781582386056490420-7884869869225180077?l=mysqltips.co.uk%2Findex.php'/&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/7884869869225180077/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=781582386056490420&amp;postID=7884869869225180077' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/posts/default/7884869869225180077'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/posts/default/7884869869225180077'/><link rel='alternate' type='text/html' href='http://mysqltips.co.uk/2009/02/how-much-intelligence-in-mysql-query.html' title='How much intelligence in the MySQL Query how much in the Code?'/><author><name>zzapper</name><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='16255832060110662275'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-781582386056490420.post-6804566015803175675</id><published>2009-02-06T14:09:00.000-08:00</published><updated>2009-02-06T14:22:28.610-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='graphs'/><category scheme='http://www.blogger.com/atom/ns#' term='online graphs'/><category scheme='http://www.blogger.com/atom/ns#' term='dynamic graphs'/><category scheme='http://www.blogger.com/atom/ns#' term='JpGraph'/><category scheme='http://www.blogger.com/atom/ns#' term='drawing graphs'/><title type='text'>Drawing Dynamic Online Graphs from MySQL Data</title><content type='html'>I was terrified at the idea of creating dynamic statistical graphs, fortunately there is a free solution where the complicated graphical stuff is reduced to a library include.  JpGraph are the providers of this PHP based solution which appears to be the de-facto package. &lt;br /&gt;&lt;br /&gt;Learn more here &lt;a href="http://www.aditus.nu/jpgraph"&gt;http://www.aditus.nu/jpgraph&lt;/a&gt; &lt;br /&gt;&lt;br /&gt;JpGraph is a Object-Oriented Graph creating library for PHP &gt;= 4.3.1 The library is completely written in PHP and ready to be used in any PHP scripts (both CGI/APXS/CLI versions of PHP are supported).&lt;br /&gt;&lt;br /&gt;The library can be used to create numerous types of graphs either on-line or written to a file. JpGraph makes it easy to draw both "quick and dirty" graphs with a minimum of code as well as complex graphs which requires a very fine grained control. The library assigns context sensitive default values for most of the parameters which minimizes the learning curve. The features are there when you need them - not as an obstacle to overcome! &lt;br /&gt;&lt;br /&gt;Curiously the MySQL part is trivial, you just have query your database for what ever data you require and then pass this to the JpGraph "plotline" function.&lt;br /&gt;&lt;br /&gt;They provide hundreds of working examples one of which should match your requirements.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/781582386056490420-6804566015803175675?l=mysqltips.co.uk%2Findex.php'/&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/6804566015803175675/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=781582386056490420&amp;postID=6804566015803175675' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/posts/default/6804566015803175675'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/posts/default/6804566015803175675'/><link rel='alternate' type='text/html' href='http://mysqltips.co.uk/2009/02/drawing-dynamic-online-graphs-from.html' title='Drawing Dynamic Online Graphs from MySQL Data'/><author><name>zzapper</name><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='16255832060110662275'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-781582386056490420.post-1546116036102618997</id><published>2009-01-30T05:59:00.000-08:00</published><updated>2009-01-30T06:02:22.151-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='search by length'/><title type='text'>Search for names of a certain length</title><content type='html'>Suppose if we want to find the names that contain exactly five characters, we use a special character "_"(underscore). The following query will list all the five letter names from the table employees.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;select * from employees where firstname like '_____';&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/781582386056490420-1546116036102618997?l=mysqltips.co.uk%2Findex.php'/&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/1546116036102618997/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=781582386056490420&amp;postID=1546116036102618997' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/posts/default/1546116036102618997'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/posts/default/1546116036102618997'/><link rel='alternate' type='text/html' href='http://mysqltips.co.uk/2009/01/search-for-names-of-certain-length.html' title='Search for names of a certain length'/><author><name>zzapper</name><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='16255832060110662275'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-781582386056490420.post-9002719578590940473</id><published>2009-01-08T14:24:00.000-08:00</published><updated>2009-01-08T14:28:43.583-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='tables'/><category scheme='http://www.blogger.com/atom/ns#' term='css'/><title type='text'>Creating Tables with CSS rather than HTML</title><content type='html'>Finally got to grips with this today, seemed pretty tricky but of course HTML tables can be troublesome as well. Nearly abandoned the attempt before I made a breakthrough and started to get a feel for it!&lt;br /&gt;&lt;br /&gt;Also understood why this method is popular, it's because it cleans up your HTML instead of having zillions of tr, td tags you can black-box all the finetuning inside the stylesheet.&lt;br /&gt;&lt;br /&gt;So should see some cleaner MySQL html templates from me now!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/781582386056490420-9002719578590940473?l=mysqltips.co.uk%2Findex.php'/&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/9002719578590940473/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=781582386056490420&amp;postID=9002719578590940473' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/posts/default/9002719578590940473'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/posts/default/9002719578590940473'/><link rel='alternate' type='text/html' href='http://mysqltips.co.uk/2009/01/creating-tables-with-css-rather-than.html' title='Creating Tables with CSS rather than HTML'/><author><name>zzapper</name><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='16255832060110662275'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-781582386056490420.post-8185244370728553062</id><published>2008-12-15T04:27:00.001-08:00</published><updated>2008-12-15T04:27:44.290-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='wordpress'/><category scheme='http://www.blogger.com/atom/ns#' term='mysql'/><category scheme='http://www.blogger.com/atom/ns#' term='Replace'/><title type='text'>Moving a Wordpress Blog to a New Domain</title><content type='html'>&lt;p&gt;To update WordPress options with the new blog location, use the following SQL command:&lt;/p&gt; &lt;p&gt;&lt;code&gt;UPDATE wp_options SET option_value = replace(option_value, 'http://www.old-domain.com', 'http://www.new-domain.com') WHERE option_name = 'home' OR option_name = 'siteurl';&lt;/code&gt;&lt;/p&gt; &lt;p&gt;After that you will need to fix URLs of the WordPress posts and pages, which translated from post slug, and stored in database wp_posts table as guid field. The URL values in this field are stored as absolute URLs instead of relative URLs, so it needs to be changed with the following SQL query:&lt;/p&gt; &lt;p&gt;&lt;code&gt;UPDATE wp_posts SET guid = replace(guid, 'http://www.old-domain.com','http://www.new-domain.com');&lt;/code&gt;&lt;/p&gt; &lt;p&gt;If you have linked internally within blog posts or pages with absolute URLs, these links will point to wrong locations after you move the blog location. Use the following SQL commands to fix all internal links to own blog in all WordPress posts and pages:&lt;/p&gt; &lt;p&gt;&lt;code&gt;UPDATE wp_posts SET post_content = replace(post_content, 'http://www.old-domain.com', 'http://www.new-domain.com');&lt;/code&gt;&lt;/p&gt;&lt;p&gt;from &lt;a href="http://www.mydigitallife.info/"&gt;http://www.mydigitallife.info&lt;/a&gt;&lt;br /&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;code&gt;&lt;br /&gt;&lt;/code&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/781582386056490420-8185244370728553062?l=mysqltips.co.uk%2Findex.php'/&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/8185244370728553062/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=781582386056490420&amp;postID=8185244370728553062' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/posts/default/8185244370728553062'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/posts/default/8185244370728553062'/><link rel='alternate' type='text/html' href='http://mysqltips.co.uk/2008/12/moving-wordpress-blog-to-new-domain.html' title='Moving a Wordpress Blog to a New Domain'/><author><name>zzapper</name><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='16255832060110662275'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-781582386056490420.post-8860016600810149298</id><published>2008-11-24T12:25:00.000-08:00</published><updated>2008-11-24T12:35:09.294-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql'/><category scheme='http://www.blogger.com/atom/ns#' term='form'/><category scheme='http://www.blogger.com/atom/ns#' term='lookup table'/><category scheme='http://www.blogger.com/atom/ns#' term='select'/><title type='text'>PHP Primitive to Create an HTML Form Dropdown from a MySQL table</title><content type='html'>$options_html=fn_make_form_selection_element($selected);&lt;br /&gt;&lt;br /&gt;function fn_make_form_selection_element($selected_value)&lt;br /&gt;{&lt;br /&gt;$select_html="";&lt;br /&gt;$query = "select * from lookup_offices order by office_id";&lt;br /&gt;$result = mysql_query($query) or die ("query not valid".mysql_error());&lt;br /&gt;&lt;br /&gt;while($row = mysql_fetch_assoc($result))&lt;br /&gt;{&lt;br /&gt;$db_value=$row['office_id'];&lt;br /&gt;$db_name=$row['office_real_name'];&lt;br /&gt;&lt;br /&gt;$option_selected='';&lt;br /&gt;if ($db_value==$selected_value) $option_selected='selected';&lt;br /&gt;$select_html.=&lt;&lt;&lt;_STR_&lt;br /&gt;&lt; option value="$db_value" $option_selected&gt;$db_name&lt; /option&gt;\n&lt;br /&gt;_STR_;&lt;br /&gt;}&lt;br /&gt;return ($select_html);&lt;br /&gt;}&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/781582386056490420-8860016600810149298?l=mysqltips.co.uk%2Findex.php'/&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/8860016600810149298/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=781582386056490420&amp;postID=8860016600810149298' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/posts/default/8860016600810149298'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/posts/default/8860016600810149298'/><link rel='alternate' type='text/html' href='http://mysqltips.co.uk/2008/11/php-primitive-to-create-html-form.html' title='PHP Primitive to Create an HTML Form Dropdown from a MySQL table'/><author><name>zzapper</name><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='16255832060110662275'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-781582386056490420.post-8697651761440525001</id><published>2008-11-18T08:33:00.000-08:00</published><updated>2008-11-18T09:00:53.461-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='substring'/><category scheme='http://www.blogger.com/atom/ns#' term='Concat'/><title type='text'>MySQL to Create an HTML Hyperlink from an URL</title><content type='html'>SELECT url,href FROM tbl_password where private = '1' and url NOT like '%squid%';&lt;br /&gt;&lt;br /&gt;update tbl_password &lt;br /&gt;set href=concat('&lt; a href="',url,'"&gt;',url,'&lt; /a&gt;') &lt;br /&gt;where private = '1' and url NOT like '%squid%';&lt;br /&gt;&lt;br /&gt;I really wanted to strip the http:// off the anchor text as well&lt;br /&gt;&lt;br /&gt;update tbl_password &lt;br /&gt;set href=concat('&lt; a href="',url,'"&gt;',SUBSTRING(url,7),'&lt; /a&gt;') &lt;br /&gt;where private = '1' and url NOT like '%squid%' ;&lt;br /&gt;&lt;br /&gt;Note here how flexible concat is with multiple parameters&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/781582386056490420-8697651761440525001?l=mysqltips.co.uk%2Findex.php'/&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/8697651761440525001/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=781582386056490420&amp;postID=8697651761440525001' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/posts/default/8697651761440525001'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/posts/default/8697651761440525001'/><link rel='alternate' type='text/html' href='http://mysqltips.co.uk/2008/11/mysql-to-create-html-hyperlink-from-url.html' title='MySQL to Create an HTML Hyperlink from an URL'/><author><name>zzapper</name><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='16255832060110662275'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-781582386056490420.post-4726472037621031742</id><published>2008-10-10T12:57:00.001-07:00</published><updated>2008-10-10T13:43:10.430-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='normalisation'/><title type='text'>MySQL Table Design : The Two Types of Table</title><content type='html'>In a simple database there will likely be two types of tables, data tables and lookup tables.&lt;br /&gt;&lt;br /&gt;A lookup table will contain say a list of Counties/States&lt;br /&gt;&lt;br /&gt;eg&lt;br /&gt;state_id,state&lt;br /&gt;1, Alabama&lt;br /&gt;2) Carolina&lt;br /&gt;&lt;br /&gt;The principle is that a lookup table defines in one place and one place only in this case the list of states. This has a posh name "Normalisation" it prevents the problems caused by different tables using slightly different names or indexes for States&lt;br /&gt;&lt;br /&gt;A Data Table contains as you might expect the data, they are usually more complex and have a unique index (primary key).&lt;br /&gt;&lt;br /&gt;I usually name my data tables tbl_xxxx and my lookup tables lu_xxx to distinguish then&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/781582386056490420-4726472037621031742?l=mysqltips.co.uk%2Findex.php'/&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/4726472037621031742/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=781582386056490420&amp;postID=4726472037621031742' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/posts/default/4726472037621031742'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/posts/default/4726472037621031742'/><link rel='alternate' type='text/html' href='http://mysqltips.co.uk/2008/10/mysql-table-design-two-types-of-table.html' title='MySQL Table Design : The Two Types of Table'/><author><name>zzapper</name><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='16255832060110662275'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-781582386056490420.post-8284336473967711591</id><published>2008-10-08T06:45:00.000-07:00</published><updated>2008-10-08T06:53:41.335-07:00</updated><title type='text'>How can you test if/when a database was last used/updated?</title><content type='html'>SHOW TABLE STATUS for database01;&lt;br /&gt;&lt;br /&gt;This lists create_time &amp;amp; update_time it is easy to visually scan to see latest update date.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/781582386056490420-8284336473967711591?l=mysqltips.co.uk%2Findex.php'/&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/8284336473967711591/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=781582386056490420&amp;postID=8284336473967711591' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/posts/default/8284336473967711591'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/posts/default/8284336473967711591'/><link rel='alternate' type='text/html' href='http://mysqltips.co.uk/2008/10/how-can-you-test-ifwhen-database-was.html' title='How can you test if/when a database was last used/updated?'/><author><name>zzapper</name><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='16255832060110662275'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-781582386056490420.post-5026481531294426429</id><published>2008-08-29T08:55:00.000-07:00</published><updated>2008-08-29T08:56:53.586-07:00</updated><title type='text'>3 Types of MySQL Comments</title><content type='html'>mysql&gt; &lt;strong class="userinput"&gt;&lt;code&gt;SELECT 1+1;     # This comment continues to the end of line&lt;/code&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;mysql&gt; &lt;strong class="userinput"&gt;&lt;code&gt;SELECT 1+1;     -- This comment continues to the end of line&lt;/code&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;mysql&gt; &lt;strong class="userinput"&gt;&lt;code&gt;SELECT 1 /* this is an in-line comment */ + 1;&lt;/code&gt;&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;mysql&gt; &lt;strong class="userinput"&gt;&lt;code&gt;SELECT 1+&lt;/code&gt;&lt;/strong&gt; &lt;strong class="userinput"&gt;&lt;code&gt;/*&lt;/code&gt;&lt;/strong&gt; &lt;strong class="userinput"&gt;&lt;code&gt;&lt;br /&gt;this is a&lt;/code&gt;&lt;/strong&gt; &lt;strong class="userinput"&gt;&lt;code&gt;multiple-line comment&lt;/code&gt;&lt;/strong&gt; &lt;strong class="userinput"&gt;&lt;code&gt;&lt;br /&gt;*/&lt;/code&gt;&lt;/strong&gt; &lt;strong class="userinput"&gt;&lt;code&gt;&lt;br /&gt;1;&lt;/code&gt;&lt;/strong&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/781582386056490420-5026481531294426429?l=mysqltips.co.uk%2Findex.php'/&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/5026481531294426429/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=781582386056490420&amp;postID=5026481531294426429' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/posts/default/5026481531294426429'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/posts/default/5026481531294426429'/><link rel='alternate' type='text/html' href='http://mysqltips.co.uk/2008/08/3-types-of-mysql-comments.html' title='3 Types of MySQL Comments'/><author><name>zzapper</name><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='16255832060110662275'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-781582386056490420.post-23326227657037784</id><published>2008-08-24T06:10:00.000-07:00</published><updated>2008-08-28T07:21:02.994-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='duplication'/><category scheme='http://www.blogger.com/atom/ns#' term='testing'/><title type='text'>A Technique for Testing an Update Safely</title><content type='html'>Create a separate table&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;create table testtable as select * from realtable;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;And execute the statement there.&lt;br /&gt;&lt;br /&gt;In fact it wouldn't hurt to have an entire duplicate test database, which you can easily create with a data dump&lt;br /&gt;&lt;p align="center"&gt;&lt;br /&gt;&lt;a href="http://www.000webhost.com/" onclick="this.href='http://www.000webhost.com/49178.html'" target="_blank"&gt;&lt;img src="http://www.000webhost.com/images/banners/120x120/banner1.gif" alt="Free Web Hosting with Website Builder" border="0" width="120" height="120" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;/p&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/781582386056490420-23326227657037784?l=mysqltips.co.uk%2Findex.php'/&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/23326227657037784/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=781582386056490420&amp;postID=23326227657037784' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/posts/default/23326227657037784'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/posts/default/23326227657037784'/><link rel='alternate' type='text/html' href='http://mysqltips.co.uk/2008/08/technique-for-testing-update-safely.html' title='A Technique for Testing an Update Safely'/><author><name>zzapper</name><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='16255832060110662275'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-781582386056490420.post-2297416712522152596</id><published>2008-08-23T04:38:00.000-07:00</published><updated>2008-08-23T04:50:09.465-07:00</updated><title type='text'>Accidently destroying data with an UPDATE</title><content type='html'>At times the syntax of MySQL can appear overly strict eg when you are hurriedly hand typing a query and it keeps throwing up a syntax error. At other times however MySQL will output no error when you might wish it would. An example of this might be string concatenation&lt;br /&gt;&lt;br /&gt;If you forgot that you needed to use Concat for this&lt;br /&gt;ie&lt;br /&gt;&lt;br /&gt;update tbl_password set url=concat('http://',url) where url not like&lt;br /&gt;'http://%' limit 1;   ### CORRECT###&lt;br /&gt;&lt;br /&gt;but instead wrote&lt;br /&gt;&lt;br /&gt;update tbl_password set url=url+'http://'  limit 1;   ### INCORRECT ###&lt;br /&gt;&lt;br /&gt;You would destroy the contents of the field URL&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/781582386056490420-2297416712522152596?l=mysqltips.co.uk%2Findex.php'/&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/2297416712522152596/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=781582386056490420&amp;postID=2297416712522152596' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/posts/default/2297416712522152596'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/posts/default/2297416712522152596'/><link rel='alternate' type='text/html' href='http://mysqltips.co.uk/2008/08/accidently-destroying-data-with-update.html' title='Accidently destroying data with an UPDATE'/><author><name>zzapper</name><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='16255832060110662275'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-781582386056490420.post-8707191480680173361</id><published>2008-08-02T04:07:00.000-07:00</published><updated>2008-08-23T04:30:46.573-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Concat'/><title type='text'>Updating Data Strings with Concat</title><content type='html'>I needed to prefix http:// before any urls that didn't already have it.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;update tbl_password set url=concat('http://',url) where url not like 'http://%';&lt;br /&gt;&lt;br /&gt;(the following is my test statement which I used to avoid the risk of destroying data, by limiting it to one record)&lt;br /&gt;&lt;br /&gt;update tbl_password set url=concat('http://',url) where url not like 'http://%' and url like '%supanames%';&lt;br /&gt;&lt;br /&gt;Alternatively limit change to one record with 'limit'&lt;br /&gt;&lt;br /&gt;update tbl_password set url=concat('http://',url) where url not like&lt;br /&gt;'http://%' limit 1;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/781582386056490420-8707191480680173361?l=mysqltips.co.uk%2Findex.php'/&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/8707191480680173361/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=781582386056490420&amp;postID=8707191480680173361' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/posts/default/8707191480680173361'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/posts/default/8707191480680173361'/><link rel='alternate' type='text/html' href='http://mysqltips.co.uk/2008/08/updating-data-strings-with-concat.html' title='Updating Data Strings with Concat'/><author><name>zzapper</name><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='16255832060110662275'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-781582386056490420.post-5304770110471253497</id><published>2008-06-10T09:04:00.000-07:00</published><updated>2008-07-26T03:38:14.851-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='dbi'/><category scheme='http://www.blogger.com/atom/ns#' term='record'/><category scheme='http://www.blogger.com/atom/ns#' term='perl'/><title type='text'>Perl DBI MySQL read a Record</title><content type='html'>A secret of programming is to have your own personal library of "primitives" I have them for Perl,PHP &amp;amp; ColdFusion MySQL routines. eg for connecting to MySQL, Inserting/Deleting/selecting records, dumping records into hashes or arrays. The following is a simple Perl DBI MySQL function.&lt;br /&gt;&lt;br /&gt;sub fn_read_record_db()&lt;br /&gt;{&lt;br /&gt;$brochure_id=shift;&lt;br /&gt;$sql=qq|select txtdevname from ytbl_development where id='$brochure_id'|;&lt;br /&gt;$sel = $dbh-&gt;prepare($sql);&lt;br /&gt;$sel-&gt;execute;&lt;br /&gt;if ($hash_ref=$sel-&gt;fetchrow_hashref())&lt;br /&gt;{&lt;br /&gt;  return $hash_ref-&gt;{'txtdevname'};&lt;br /&gt;}&lt;br /&gt;return 'Not Found';&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Click &lt;a href="http://www.000webhost.com/49178.html"&gt;here &lt;/a&gt;Free PHP/MySQL/cPanel Webhosting No ads no catches, I didn't believe it either!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/781582386056490420-5304770110471253497?l=mysqltips.co.uk%2Findex.php'/&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/5304770110471253497/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=781582386056490420&amp;postID=5304770110471253497' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/posts/default/5304770110471253497'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/posts/default/5304770110471253497'/><link rel='alternate' type='text/html' href='http://mysqltips.co.uk/2008/06/perl-dbi-mysql-record-one-record.html' title='Perl DBI MySQL read a Record'/><author><name>zzapper</name><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='16255832060110662275'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-781582386056490420.post-4678025516652175190</id><published>2008-06-06T15:23:00.000-07:00</published><updated>2008-06-06T15:35:16.972-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='debugging'/><category scheme='http://www.blogger.com/atom/ns#' term='CLI'/><category scheme='http://www.blogger.com/atom/ns#' term='GUI'/><title type='text'>Test  your MySQL queries inside a MySQL GUI before coding them</title><content type='html'>Before you start coding your application with PHP or whatever remember to test out your MySQL in your MySQL GUI such as &lt;a href="http://www.shareit.com/affiliate.html?publisherid=33634&amp;amp;affiliateid=200010795&amp;amp;target=http://www.webyog.com/"&gt;SQLYOG&lt;/a&gt; or even the CLI&lt;br /&gt;&lt;br /&gt;What are the advantages?&lt;br /&gt;&lt;ul&gt;&lt;li&gt;You don't have to worry about the Script/MySQL syntax clashes (quoting etc)&lt;br /&gt;&lt;/li&gt;&lt;li&gt;You only have to think MySQL and not say PHP as well&lt;/li&gt;&lt;li&gt;You can see the data produced or not produced&lt;/li&gt;&lt;li&gt;You can test your concepts&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/781582386056490420-4678025516652175190?l=mysqltips.co.uk%2Findex.php'/&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/4678025516652175190/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=781582386056490420&amp;postID=4678025516652175190' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/posts/default/4678025516652175190'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/posts/default/4678025516652175190'/><link rel='alternate' type='text/html' href='http://mysqltips.co.uk/2008/06/test-your-mysql-queries-inside-mysql.html' title='Test  your MySQL queries inside a MySQL GUI before coding them'/><author><name>zzapper</name><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='16255832060110662275'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-781582386056490420.post-2591247594500377267</id><published>2008-06-06T15:11:00.000-07:00</published><updated>2008-06-06T15:21:51.223-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='aide-memoire'/><category scheme='http://www.blogger.com/atom/ns#' term='templates'/><title type='text'>MySQL Standard Query Templates (Aide-Memoire)</title><content type='html'>Create a grep-able text file with the standard MySQL queries this will help you recall the different query structure  of update/insert/select/delete add to your list everytime you write something useful:-&lt;br /&gt;(This wont look too good inside this blog but should copy/paste OK)&lt;br /&gt;&lt;br /&gt;&lt;span style="font-size:85%;"&gt;template: alter table activity_log add column loginemail varchar(40) first;&lt;br /&gt;template: insert into tbl_xxx (field1) values ('value1')&lt;br /&gt;template: update employee_data set salary=220000, perks=55000 where title='ceo';&lt;br /&gt;template: update tbl_websitepages set page_content=replace (page_content,'http://www.site.co.uk/website/cms/','/website/images/cms/');&lt;br /&gt;template: insert into bad_table2(id,name) select id,name from bad_temp2;&lt;br /&gt;template: into tbl_music_selected (registrant_email,music_id,music_title) select '$registrant_email',music_id,music_title from tbl_music where music_id='$music_id'&lt;br /&gt;template: select * from tbl_lighter_note ORDER BY RAND() LIMIT 1&lt;br /&gt;template: select * from tbl_orders order by count limit 0,10 (select top ten)&lt;br /&gt;template: update tbl_lighter_note set count=count+1&lt;br /&gt;template: select * from ytbl_region_county_lookup as t1 inner join ytbl_mapregions  mp on t1.region_id = mp.intID where t1.region_id = '14' order by t2.DivisionName;&lt;br /&gt;template: update tbl_readings set abc = ucase(reading_title); #will automatically truncate if field shorter&lt;br /&gt;template: update tbl_readings as r1,tbl_readings3 as r3 set r1.reading_content= r3.reading_content,r1.abc=r3.abc,r1.reading_category=r3.reading_category where r1.record_id=r3.record_id; #update taking data from another table (join)&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/781582386056490420-2591247594500377267?l=mysqltips.co.uk%2Findex.php'/&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/2591247594500377267/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=781582386056490420&amp;postID=2591247594500377267' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/posts/default/2591247594500377267'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/posts/default/2591247594500377267'/><link rel='alternate' type='text/html' href='http://mysqltips.co.uk/2008/06/mysql-standard-query-templates-aide.html' title='MySQL Standard Query Templates (Aide-Memoire)'/><author><name>zzapper</name><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='16255832060110662275'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-781582386056490420.post-8660437846315634988</id><published>2008-05-17T07:44:00.000-07:00</published><updated>2008-05-17T07:54:35.221-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='date functions'/><title type='text'>Querying By Date</title><content type='html'>We are so frequently required to create date based queries, eg how many orders last week, last month, how many orders between two dates. It is necessary to avoid the trap of treating date as a number, instead convert the date into a handy unit such as days&lt;br /&gt;&lt;br /&gt;# select all records from today&lt;br /&gt;select * from tbl_orders where TO_DAYS(NOW()) = TO_DAYS(dtmdevdate);&lt;br /&gt;&lt;br /&gt;# select all records from last three days&lt;br /&gt;select * from tbl_orders where  (TO_DAYS(NOW())-3) &gt; TO_DAYS(orderdate);&lt;br /&gt;&lt;br /&gt;MySQL provides a whole range of date functions become familiar with them here&lt;br /&gt;&lt;br /&gt;&lt;a href="http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html"&gt;http://dev.mysql.com/doc/refman/5.0/en/date-and-time-functions.html&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/781582386056490420-8660437846315634988?l=mysqltips.co.uk%2Findex.php'/&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/8660437846315634988/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=781582386056490420&amp;postID=8660437846315634988' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/posts/default/8660437846315634988'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/posts/default/8660437846315634988'/><link rel='alternate' type='text/html' href='http://mysqltips.co.uk/2008/05/querying-by-date.html' title='Querying By Date'/><author><name>zzapper</name><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='16255832060110662275'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-781582386056490420.post-8552757599934843500</id><published>2008-04-16T08:23:00.000-07:00</published><updated>2008-04-16T11:11:16.437-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='mysql'/><category scheme='http://www.blogger.com/atom/ns#' term='algorithm'/><category scheme='http://www.blogger.com/atom/ns#' term='meta data'/><title type='text'>Creating a Derived Data Column (for efficiency)</title><content type='html'>Hi&lt;br /&gt;Frequently we query our database for a value but then have to always do the same manipulation on it before we can use it. Well it can often be useful to do this "once" in the database and then store the manipulated value in a separate column of the database. &lt;br /&gt;&lt;br /&gt;Here is a very simple example&lt;br /&gt;INSERT INTO tbl_name (col1,col2) VALUES(15,col1*3.14159);&lt;br /&gt;&lt;br /&gt;Where col2 is set to the value of col1*pi&lt;br /&gt;&lt;br /&gt;You could also do more complex calculation/filtering/shortening in your code eg php,ASP etc&lt;br /&gt;&lt;br /&gt;Can you see the power of this technique?&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/781582386056490420-8552757599934843500?l=mysqltips.co.uk%2Findex.php'/&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/8552757599934843500/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=781582386056490420&amp;postID=8552757599934843500' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/posts/default/8552757599934843500'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/posts/default/8552757599934843500'/><link rel='alternate' type='text/html' href='http://mysqltips.co.uk/2008/04/creating-derived-data-column-for.html' title='Creating a Derived Data Column (for efficiency)'/><author><name>zzapper</name><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='16255832060110662275'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-781582386056490420.post-622916319385926524</id><published>2008-01-29T09:29:00.000-08:00</published><updated>2008-01-29T09:34:07.373-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='backup'/><category scheme='http://www.blogger.com/atom/ns#' term='SQLYOG'/><category scheme='http://www.blogger.com/atom/ns#' term='Recovery'/><title type='text'>Recovering a database from the raw .frm .MYI .MYD files on Vista</title><content type='html'>(All this presupposes you failed to do a recent &amp; proper backup/dump of your data, but that's why you are reading this)&lt;br /&gt;&lt;br /&gt;MySQL requires its datafiles ,*.MYI,*.frm,*.MYD to have exactly the right permissions and ownership otherwise MySQL refuses to see them.&lt;br /&gt;Now this is a problem for me on Vista (de-Vista-ted) because I still haven't worked how to change ownership.&lt;br /&gt;&lt;br /&gt;Solution:&lt;br /&gt;1) In new Database create a table with same name , populate with a record or two (doesnt have to have same structure)&lt;br /&gt;1a) I didnt need to do this as I used a month old backup&lt;br /&gt;2) Use Windows Explorer to copy your "good" frm,MYI,MYD on top of the dummy files you created&lt;br /&gt;3) They will automatically inherit the correct owner/permissions&lt;br /&gt;4) When I did this, I was saddened to see however that I couldn't see my new records (probably due to different MySQL versions)&lt;br /&gt;5) I did a Table diagnostics and saw there was an error (using SQLYOG)&lt;br /&gt;6) Did a Repair Table in same Table Diagnostics and wow there were my lovely records!&lt;br /&gt;7) Implement an automatic nightly backup of your databases&lt;br /&gt;&lt;br /&gt;So it is possible to recover your database from the raw files, but watch out for :-&lt;br /&gt;file permissions &amp; file ownership and try to have the same MySQL version. &lt;br /&gt;You could do all this on a spare PC and then do a proper backup/dump which is then portable!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/781582386056490420-622916319385926524?l=mysqltips.co.uk%2Findex.php'/&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/622916319385926524/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=781582386056490420&amp;postID=622916319385926524' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/posts/default/622916319385926524'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/posts/default/622916319385926524'/><link rel='alternate' type='text/html' href='http://mysqltips.co.uk/2008/01/recovering-database-from-raw-frm-myi.html' title='Recovering a database from the raw .frm .MYI .MYD files on Vista'/><author><name>zzapper</name><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='16255832060110662275'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-781582386056490420.post-2162334938913059991</id><published>2007-11-19T12:20:00.000-08:00</published><updated>2007-11-19T12:22:35.215-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='Technorati'/><category scheme='http://www.blogger.com/atom/ns#' term='Blog Search Engine'/><title type='text'>Technorati the Specialist Blog Search Engine</title><content type='html'>I'm trying to get this blog registered with Technorati the Specialist Blog Search Engine.&lt;br /&gt;&lt;br /&gt;I have to post this to show that I own the Blog&lt;br /&gt;&lt;br /&gt;&lt;a href="http://technorati.com/claim/w8tsa5nqx8" rel="me"&gt;Technorati Profile&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/781582386056490420-2162334938913059991?l=mysqltips.co.uk%2Findex.php'/&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/2162334938913059991/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=781582386056490420&amp;postID=2162334938913059991' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/posts/default/2162334938913059991'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/posts/default/2162334938913059991'/><link rel='alternate' type='text/html' href='http://mysqltips.co.uk/2007/11/im-trying-to-get-this-blog-registered.html' title='Technorati the Specialist Blog Search Engine'/><author><name>zzapper</name><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='16255832060110662275'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-781582386056490420.post-4167729027834414560</id><published>2007-11-16T06:39:00.000-08:00</published><updated>2007-11-16T06:56:17.564-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='php'/><category scheme='http://www.blogger.com/atom/ns#' term='phprunner'/><title type='text'>PHPRunner saved me from a Nervous Breakdown!</title><content type='html'>We know we have to work cleverer rather than harder.&lt;br /&gt;&lt;br /&gt;I was working on a large PHP/MySQL website where the specification kept changing. It was bad enough redesigning that data and recoding the PHP all the time. Fortunately by using PHPRunner I was able to rebuild the admin side each time in just minutes. Using PHPrunner you can build your PHP Pages (or ASP using ASPRunner) which allow you to search and list your records and subsequently create, modify or delete them. You know that tedious repetitive stuff.&lt;br /&gt;&lt;br /&gt;I know PHPrunner can also build the Web side as well, but I haven't looked into that yet , but will let you know.&lt;br /&gt;&lt;br /&gt;There is an evaluation version, download it and get hooked!&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.xlinesoft.com/phprunner/?1087"&gt;Download Here&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/781582386056490420-4167729027834414560?l=mysqltips.co.uk%2Findex.php'/&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/4167729027834414560/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='https://www.blogger.com/comment.g?blogID=781582386056490420&amp;postID=4167729027834414560' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/posts/default/4167729027834414560'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/781582386056490420/posts/default/4167729027834414560'/><link rel='alternate' type='text/html' href='http://mysqltips.co.uk/2007/11/phprunner-saved-me-from-nervous.html' title='PHPRunner saved me from a Nervous Breakdown!'/><author><name>zzapper</name><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='16255832060110662275'/></author><thr:total xmlns:thr='http://purl.org/syndication/thread/1.0'>0</thr:total></entry></feed>