<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Running A Website &#187; wordpress plugins</title>
	<atom:link href="http://www.runningawebsite.com/tag/wordpress-plugins/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.runningawebsite.com</link>
	<description>Practical tips and advice for running a successful website!</description>
	<lastBuildDate>Wed, 18 Aug 2010 22:44:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>WordPress Plugin Tip &#8211; MySQL Transactions with $wpdb</title>
		<link>http://www.runningawebsite.com/wordpress-plugin-tip-mysql-transactions-with-wpdb/</link>
		<comments>http://www.runningawebsite.com/wordpress-plugin-tip-mysql-transactions-with-wpdb/#comments</comments>
		<pubDate>Tue, 01 Jun 2010 09:00:09 +0000</pubDate>
		<dc:creator>Dan Harrison</dc:creator>
				<category><![CDATA[Wordpress]]></category>
		<category><![CDATA[wordpress plugins]]></category>
		<category><![CDATA[wordpress themes]]></category>

		<guid isPermaLink="false">http://www.runningawebsite.com/?p=1000</guid>
		<description><![CDATA[This tip is more for WordPress theme and plugin developers. I&#8217;ve been working on a client project that required MySQL transactions, as I needed to perform multiple deletions on multiple tables, where the data was interdependent. Since I was writing a WordPress plugin, I wanted a way of doing a MySQL database transaction, using the ...]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.runningawebsite.com%2Fwordpress-plugin-tip-mysql-transactions-with-wpdb%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.runningawebsite.com%2Fwordpress-plugin-tip-mysql-transactions-with-wpdb%2F&amp;source=DanJHarrison&amp;style=normal&amp;service=bit.ly" height="61" width="50" /><br />
			</a>
		</div>
<p><img src="http://www.runningawebsite.com/wp-content/uploads/2010/05/Wordpress-Logo-Newspaper-Style-150x150.jpg" alt="" title="Wordpress Logo Newspaper Style" width="150" height="150" class="alignleft size-thumbnail wp-image-1002" /></p>
<p>This tip is more for WordPress theme and plugin developers. I&#8217;ve been working on a client project that required MySQL transactions, as I needed to perform multiple deletions on multiple tables, where the data was interdependent. Since I was writing a WordPress plugin, I wanted a way of doing a <strong>MySQL database transaction</strong>, <strong>using the WordPress database object</strong> <a href="http://codex.wordpress.org/Function_Reference/wpdb_Class">$wpdb</a>.</p>
<p><span id="more-1000"></span></p>
<p>When you create a connection to a MySQL database, you end up with a connection handle. This is essentially a way of communicating with the database down the same pipe. When you render a page in WordPress (front end or admin area), the <strong>$wpdb</strong> database object has already been initialised and opened up a connection to the database. Therefore we can recycle this database connection for our own needs. </p>
<p>The $wpdb object saves the database handle as <strong>$wpdb->dbh</strong> (<strong>dbh</strong> = <strong>D</strong>ata<strong>b</strong>ase <strong>H</strong>andle). Therefore we just use <strong>$wpdb->dbh</strong> in place of our normal database handle that we&#8217;d otherwise use in PHP.</p>
<h3>Code Example</h3>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #339933;">&amp;</span>lt<span style="color: #339933;">;</span>?php
<span style="color: #000000; font-weight: bold;">global</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// @ prefix used to suppress errors, but you should do your own</span>
<span style="color: #666666; font-style: italic;">// error checking by checking return values from each mysql_query()</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Start Transaction</span>
<span style="color: #339933;">@</span><span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;BEGIN&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dbh</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Do some expensive/related queries here</span>
<span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;DELETE FROM table WHERE form_id = '1' &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;DELETE FROM data WHERE form_id = '1' &quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$error</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #666666; font-style: italic;">// Error occured, don't save any changes</span>
    <span style="color: #339933;">@</span><span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;ROLLBACK&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dbh</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #666666; font-style: italic;">// All ok, save the changes</span>
   <span style="color: #339933;">@</span><span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;COMMIT&quot;</span><span style="color: #339933;">,</span> <span style="color: #000088;">$wpdb</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">dbh</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Based on this, you can do your usual PHP and WordPress magic to do what you need. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.runningawebsite.com/wordpress-plugin-tip-mysql-transactions-with-wpdb/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>WP Portfolio Plugin V1.0 Released</title>
		<link>http://www.runningawebsite.com/wp-portfolio-plugin-v10-released/</link>
		<comments>http://www.runningawebsite.com/wp-portfolio-plugin-v10-released/#comments</comments>
		<pubDate>Wed, 20 May 2009 21:00:37 +0000</pubDate>
		<dc:creator>Dan Harrison</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[wordpress plugins]]></category>
		<category><![CDATA[WP Portfolio]]></category>

		<guid isPermaLink="false">http://www.danharrison.co.uk/?p=190</guid>
		<description><![CDATA[After lots of work, I&#8217;ve publically released my first wordpress plugin called WP Portfolio, which is now available directly from the WordPress Plugin Database. The WP Portfolio plugin allows you to create a list of the websites you own or developed, which are then published on a page on your website. The plugin automatically generates ...]]></description>
			<content:encoded><![CDATA[<div class="tweetmeme_button" style="">
			<a href="http://api.tweetmeme.com/share?url=http%3A%2F%2Fwww.runningawebsite.com%2Fwp-portfolio-plugin-v10-released%2F"><br />
				<img src="http://api.tweetmeme.com/imagebutton.gif?url=http%3A%2F%2Fwww.runningawebsite.com%2Fwp-portfolio-plugin-v10-released%2F&amp;source=DanJHarrison&amp;style=normal&amp;service=bit.ly" height="61" width="50" /><br />
			</a>
		</div>
<div id="attachment_196" class="wp-caption aligncenter" style="width: 293px"><a href="http://www.runningawebsite.com/wp-content/uploads/2009/05/portfolio-in-action.png"><img src="http://www.runningawebsite.com/wp-content/uploads/2009/05/portfolio-in-action-283x300.png" alt="" title="Portfolio In Action" width="283" height="300" class="size-medium wp-image-196" /></a><p class="wp-caption-text">Portfolio In Action</p></div>
<p>After lots of work, I&#8217;ve publically released my first wordpress plugin called <a href="http://wordpress.org/extend/plugins/wp-portfolio">WP Portfolio</a>, which is now available directly from the <a href="http://wordpress.org/extend/plugins/">WordPress Plugin Database</a>.</p>
<p>The WP Portfolio plugin allows you to create a list of the websites you own or developed, which are then published on a page on your website. The plugin automatically generates thumbnails of each of your sites for you too. An example of the plugin in action is on <a href="http://www.runningawebsite.com/portfolio/">my own portfolio page</a>.<span id="more-190"></span></p>
<div id="attachment_197" class="wp-caption aligncenter" style="width: 310px"><a href="http://www.runningawebsite.com/wp-content/uploads/2009/05/portfolio-in-admin-area.png"><img src="http://www.runningawebsite.com/wp-content/uploads/2009/05/portfolio-in-admin-area-300x162.png" alt="" title="Portfolio Admin Area" width="300" height="162" class="size-medium wp-image-197" /></a><p class="wp-caption-text">Portfolio Admin Area</p></div>
<p>The WP portfolio plugin is ideal if you want to advertise all of the sites you work on, but where you don&#8217;t want to spend ages creating thumbnails. You have complete control over the HTML and CSS to render the thumbnails, but a default layout is provided to get you going. The thumbnails are generated using a free account on <a href="http://www.shrinktheweb.com">Shrink The Web</a>.</p>
<p>Here&#8217;s summary of what you can do with the plugin:</p>
<ul>
<li>Create a list of your websites with a name, URL and description</li>
<li>Group similar websites together, with a title and description for that group.</li>
<li>Automatically generate thumbnails in a small (120 x 90), large (200 x 150) or extra large size (320 x 240).</li>
<li>Adjust the number of days to cache the thumbnail on your site (to reduce load times)</li>
<li>Customise the HTML and CSS used to render the site and group fields.</li>
</ul>
<p>Any feedback, suggestions and ideas are greatly welcomed.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.runningawebsite.com/wp-portfolio-plugin-v10-released/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
