<?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>Christopher Shennan's Blog &#187; Symfony</title>
	<atom:link href="http://www.chrisshennan.com/category/php/symfony/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.chrisshennan.com</link>
	<description>A day in the life of...</description>
	<lastBuildDate>Wed, 01 Sep 2010 13:00:38 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Method Signatures &#8211; Pass values as individual parameters or an option array?</title>
		<link>http://www.chrisshennan.com/2010/08/25/method-signatures-pass-values-as-individual-parameters-or-an-option-array/</link>
		<comments>http://www.chrisshennan.com/2010/08/25/method-signatures-pass-values-as-individual-parameters-or-an-option-array/#comments</comments>
		<pubDate>Wed, 25 Aug 2010 11:07:47 +0000</pubDate>
		<dc:creator>Christopher Shennan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[method signatures]]></category>
		<category><![CDATA[options array]]></category>
		<category><![CDATA[parameter passing]]></category>
		<category><![CDATA[parameters vs option array]]></category>
		<category><![CDATA[parameters vs options]]></category>
		<category><![CDATA[symfony options array]]></category>

		<guid isPermaLink="false">http://www.chrisshennan.com/?p=330</guid>
		<description><![CDATA[Over the last few months I have been working with Symfony and have got used to passing values to methods via an options array but I have recently had to pick up an older project in which the values are passed to the methods by individual parameters. 
This has given me a good opportunity to [...]]]></description>
			<content:encoded><![CDATA[<h4><span style="font-weight: normal;">Over the last few months I have been working with Symfony and have got used to passing values to methods via an options array but I have recently had to pick up an older project in which the values are passed to the methods by individual parameters. </span></h4>
<h4><span style="font-weight: normal;">This has given me a good opportunity to evaluate both techniques and determine my personal preference for working.</span></h4>
<p>The more traditional technique is to pass values to methods using individual parameters as in the example below:-</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> someMethod<span style="color: #009900;">&#40;</span><span style="color: #000088;">$name</span><span style="color: #339933;">,</span> <span style="color: #000088;">$age</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">null</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// do something</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>The benefit I have found with this method is that you can clearly identify what needs to be passed to the method, however, if you need to change the method to include an additional parameter it means that you have to update every call to this method so that every parameter is specified.<br />
<span id="more-330"></span><br />
An alternative (and my personal preference) is to used an option array like in the following example</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> someMethod<span style="color: #009900;">&#40;</span><span style="color: #000088;">$options</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
  <span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$options</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'name'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
  <span style="color: #666666; font-style: italic;">// do something</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>In this case, if you need to add an extra parameter to the method you can simply add the value to the options array and update the functionality within the method.  You do not necessarily need to update the calls to this method that are already in place  because they should still work fine provided the updated functionality is defined in such a way that it allows for the new parameter to be optional.</p>
<p>In addition, I feel that if you provide decent documentation regarding the options array (which should include a list of all the options values allowed), especially if it can be picked up via auto-completion in IDEs such as <a href="http://www.netbeans.com/" target="_blank">Netbeans</a>, then this is just as easy to use as methods which are defined to accept individual parameters.</p>
<h4>References</h4>
<p><a href="http://weblogtoolscollection.com/archives/2010/02/25/passing-parameters-as-variables-vs-passing-parameters-as-an-array/" target="_blank">http://weblogtoolscollection.com/archives/2010/02/25/passing-parameters-as-variables-vs-passing-parameters-as-an-array/</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.chrisshennan.com/2010/08/25/method-signatures-pass-values-as-individual-parameters-or-an-option-array/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Raw SQL from Doctrine Query Object &#8211; Revised</title>
		<link>http://www.chrisshennan.com/2009/12/07/raw-sql-from-doctrine-query-object-revised/</link>
		<comments>http://www.chrisshennan.com/2009/12/07/raw-sql-from-doctrine-query-object-revised/#comments</comments>
		<pubDate>Mon, 07 Dec 2009 19:47:21 +0000</pubDate>
		<dc:creator>Christopher Shennan</dc:creator>
				<category><![CDATA[Symfony]]></category>
		<category><![CDATA[doctine]]></category>
		<category><![CDATA[doctrine query object]]></category>
		<category><![CDATA[raw sql]]></category>

		<guid isPermaLink="false">http://www.chrisshennan.com/?p=232</guid>
		<description><![CDATA[A few months ago I posted an article taking about how to get the raw SQL from a Doctrine Query Object but with the release of Symfony 1.3 and Symfony 1.4 it would appear that the code no longer works.  As a result I&#8217;ve updated the code to work with Symfony 1.2 &#8211; 1.4 and [...]]]></description>
			<content:encoded><![CDATA[<p>A few months ago I posted an article taking about how to get the <a href="/2009/09/22/raw-sql-from-a-doctrine-query-object/" target="_self">raw SQL from a Doctrine Query Object</a> but with the release of <a href="http://www.symfony-project.org/installation/1_3" target="_blank">Symfony 1.3</a> and <a href="http://www.symfony-project.org/installation/1_4" target="_blank">Symfony 1.4</a> it would appear that the code no longer works.  As a result I&#8217;ve updated the code to work with Symfony 1.2 &#8211; 1.4 and you can find the updated source below:-<br />
<span id="more-232"></span></p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> get_raw_sql<span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span> instanceof Doctrine_Query<span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        throw <span style="color: #000000; font-weight: bold;">new</span> sfException<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Not an instanse of a Doctrine Query'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">limit</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</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: #990000;">is_callable</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'buildSqlQuery'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #000088;">$queryString</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">buildSqlQuery</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$query_params</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getParams</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$params</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$query_params</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'where'</span><span style="color: #009900;">&#93;</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: #000088;">$queryString</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getSql</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
        <span style="color: #000088;">$params</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getParams</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #000088;">$queryStringParts</span> <span style="color: #339933;">=</span> <span style="color: #990000;">split</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'\?'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$queryString</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$iQC</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$queryString</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$params</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$param</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">is_numeric</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$param</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$queryString</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$queryStringParts</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$iQC</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$param</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">is_bool</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$param</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$queryString</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$queryStringParts</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$iQC</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$param</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">1</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: #000088;">$queryString</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$queryStringParts</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$iQC</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'\''</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$param</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'\''</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
&nbsp;
        <span style="color: #000088;">$iQC</span><span style="color: #339933;">++;</span>
   <span style="color: #009900;">&#125;</span>
   <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$iQC</span><span style="color: #339933;">;</span><span style="color: #000088;">$iQC</span> <span style="color: #339933;">&lt;</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$queryStringParts</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000088;">$iQC</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
       <span style="color: #000088;">$queryString</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$queryStringParts</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$iQC</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
&nbsp;
    <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$queryString</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>I hope that it proves useful.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chrisshennan.com/2009/12/07/raw-sql-from-doctrine-query-object-revised/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>TRUNCATE TABLE with Symfony and Doctrine</title>
		<link>http://www.chrisshennan.com/2009/11/20/truncate-table-with-symfony-and-doctrine/</link>
		<comments>http://www.chrisshennan.com/2009/11/20/truncate-table-with-symfony-and-doctrine/#comments</comments>
		<pubDate>Fri, 20 Nov 2009 20:59:25 +0000</pubDate>
		<dc:creator>Christopher Shennan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[doctrine truncate table]]></category>
		<category><![CDATA[mysql truncate table]]></category>
		<category><![CDATA[symfony import routines]]></category>
		<category><![CDATA[symfony truncate table]]></category>

		<guid isPermaLink="false">http://www.chrisshennan.com/?p=178</guid>
		<description><![CDATA[I am often importing data into a symfony project from an existing site or a CSV file and re-writing this data into the fixtures.yml is usually too complicated or time consuming so I end up writing bespoke import actions.
While I am writing these actions I often find that I have to delete the contents of [...]]]></description>
			<content:encoded><![CDATA[<p>I am often importing data into a symfony project from an existing site or a CSV file and re-writing this data into the fixtures.yml is usually too complicated or time consuming so I end up writing bespoke import actions.</p>
<p>While I am writing these actions I often find that I have to delete the contents of the MySQL tables as you can never write the routine complete and accurate in one go so as you build it up in smaller steps you find that you have to get rid of the previously old data.</p>
<p>This presented me with 2 problems:-</p>
<ul>
<li>Using DELETE FROM [TABLENAME] does not reset the auto-incrementing fields so if you have anything that is based on the id during the rest of the import then you&#8217;re going to have issues.</li>
<li>There is a lot of clicking in phpMyAdmin to empty the tables, especially if you forget about the foreign key relationships.</li>
</ul>
<p><span id="more-178"></span></p>
<p>I found that MySQL had a TRUNCATE TABLE but this is not directly available via Doctrine as the TRUNCATE TABLE is function of the type of database you are using and Doctrine cannot assume you are always using MySQL so therefore it cannot provide a generic method to call it.</p>
<p>Having said that it was not too difficult to run the TRUNCATE TABLE from within my Symfony project.  All I had to do was add the following lines of code to an action within the actions.class.php for my import module and now it empties each table I have defined before importing the data and it also resets the auto-incrememt ids all my tables start from id = 1 each time I run the import.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$doctrine</span> <span style="color: #339933;">=</span> Doctrine_Manager<span style="color: #339933;">::</span><span style="color: #004000;">getInstance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getCurrentConnection</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getDbh</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$doctrine</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'TRUNCATE TABLE order_items'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$doctrine</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'TRUNCATE TABLE orders'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">unset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$doctrine</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Be careful which order you run the TRUNCATE TABLE calls so you avoid the foreign key relationship issues.</p>
<p>Let me know if this helps you out.  Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chrisshennan.com/2009/11/20/truncate-table-with-symfony-and-doctrine/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Raw SQL from a Doctrine Query Object</title>
		<link>http://www.chrisshennan.com/2009/09/22/raw-sql-from-a-doctrine-query-object/</link>
		<comments>http://www.chrisshennan.com/2009/09/22/raw-sql-from-a-doctrine-query-object/#comments</comments>
		<pubDate>Tue, 22 Sep 2009 19:01:49 +0000</pubDate>
		<dc:creator>Christopher Shennan</dc:creator>
				<category><![CDATA[SQL]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[doctrine]]></category>
		<category><![CDATA[PHP]]></category>

		<guid isPermaLink="false">http://www.chrisshennan.com/?p=138</guid>
		<description><![CDATA[This has been updated to work with Symfony 1.3/1.4 &#8211; Please go to the updated article:  Raw SQL from Doctrine Query Object – Revised
As my use of Symfony is increasing I find myself frustrated that there doesn&#8217;t appear to be an easy way to get the raw SQL from a doctrine query object so [...]]]></description>
			<content:encoded><![CDATA[<p><strong>This has been updated to work with Symfony 1.3/1.4 &#8211; Please go to the updated article:  <a href="/2009/12/07/raw-sql-from-doctrine-query-object-revised/">Raw SQL from Doctrine Query Object – Revised</a></strong></p>
<p>As my use of Symfony is increasing I find myself frustrated that there doesn&#8217;t appear to be an easy way to get the raw SQL from a doctrine query object so I can simply output it and paste it into phpMyAdmin to debug problems with the SQL.  I may be wrong about this but as yet I have not found a built in function to perform this operation.</p>
<p>Sure I am able to output the query with the &#8220;?&#8221; indicating where the necessary values are to go and I can also easily output the array of query parameters so I can substitute these manually but this takes time and it would be much much simpler and quicker to just output the whole query with the substitution already done so it&#8217;s a simply copy and paste of the raw SQL from the doctrine query object straight into phpMyAdmin.</p>
<p>I have wrote a quick function to do this and I had meant to post this for a while but I just have not had the chance to get round to it until now.<br />
<span id="more-138"></span><br />
The code for this is can be found below:-</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">function</span> get_raw_sql<span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">limit</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$queryStringParts</span> <span style="color: #339933;">=</span> <span style="color: #990000;">split</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'\?'</span><span style="color: #339933;">,</span> <span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getSQL</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$iQC</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">0</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$queryString</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$query</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getParams</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$param</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">is_numeric</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$param</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$queryString</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$queryStringParts</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$iQC</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$param</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">elseif</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">is_bool</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$param</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
            <span style="color: #000088;">$queryString</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$queryStringParts</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$iQC</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$param</span><span style="color: #339933;">*</span><span style="color: #cc66cc;">1</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: #000088;">$queryString</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$queryStringParts</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$iQC</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'\''</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$param</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">'\''</span><span style="color: #339933;">;</span>
        <span style="color: #009900;">&#125;</span>
        <span style="color: #000088;">$iQC</span><span style="color: #339933;">++;</span>
   <span style="color: #009900;">&#125;</span>
&nbsp;
   <span style="color: #b1b100;">for</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$iQC</span><span style="color: #339933;">;</span><span style="color: #000088;">$iQC</span> <span style="color: #339933;">&lt;</span> <span style="color: #990000;">count</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$queryStringParts</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span><span style="color: #000088;">$iQC</span><span style="color: #339933;">++</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
       <span style="color: #000088;">$queryString</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$queryStringParts</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$iQC</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
   <span style="color: #009900;">&#125;</span>
   <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$queryString</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>In my case this is a global function but it could very well be written as a static function in a debug class.</p>
<p>$query is a Doctrine Query object and this function iterates round the parameters for the query string and replaces each instance of a &#8220;?&#8221; with the corresponding variable.  It has a crude (but fairly effective so far) method of determine whether it&#8217;s a string, number or boolean when performing this substitution and so far this works well in all the cases I&#8217;ve used it.</p>
<p>The $query->limit(0); is very important as the $query->getSQL() function does not work properly in this context if a limit is specified on the query so as we are wanting to debug the SQL and a majority of the time we are not concerned with the limit I have opted to remove this from this routine.</p>
<p>Hopefully this will allow you to save some time and effort trying to get the raw SQL from your doctrine query objects and I would appreciated any comments, thoughts or ideas you may have for improvement.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chrisshennan.com/2009/09/22/raw-sql-from-a-doctrine-query-object/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Why you should answer your own posts?</title>
		<link>http://www.chrisshennan.com/2009/08/24/why-you-should-answer-your-own-posts/</link>
		<comments>http://www.chrisshennan.com/2009/08/24/why-you-should-answer-your-own-posts/#comments</comments>
		<pubDate>Mon, 24 Aug 2009 20:18:15 +0000</pubDate>
		<dc:creator>Christopher Shennan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Symfony]]></category>

		<guid isPermaLink="false">http://www.chrisshennan.com/?p=127</guid>
		<description><![CDATA[How many times have you searched for the answer to a problem in Google to find nothing but forums with people who have the same questions but no solutions posted even though the question was raised months, even years earlier?  
If you post a question and no-one managed to provide you with an answer [...]]]></description>
			<content:encoded><![CDATA[<p>How many times have you searched for the answer to a problem in Google to find nothing but forums with people who have the same questions but no solutions posted even though the question was raised months, even years earlier?  </p>
<p>If you post a question and no-one managed to provide you with an answer do you:-</p>
<ul>
<li>post up your solution when you&#8217;ve found it? or</li>
<li>simply forget about the post and leave everyone else to figure it out themselves too?</li>
</ul>
<p>Unfortunately there are a number of people in the latter category (myself included from time to time) and being a web developer means I run into this type of issue more than I would like but, I&#8217;ve recently come across yet another great reason why you should go back and answer your own question when you have managed to work out the answer.<br />
<span id="more-127"></span><br />
A few months ago I was working for <a href="http://www.alienationdigital.co.uk" target="_blank">Alienation Digital</a> in Glasgow and I had a problem with creating a <a href="http://forum.symfony-project.org/index.php/mv/tree/20144/76457/" target="_blank">custom validator using a callback in Symfony</a> and I posted the problem to the Symfony forums, and later, the solution I used to rectify the problem.</p>
<p>Fast forward a few months and you now find me working for <a href="http://www.line.uk.com" target="_blank">Line Digital</a> in Edinburgh and I&#8217;m now working on a new project which has a very similar problem.  Obviously I don&#8217;t have access to the code I wrote while at <a href="http://www.alienationdigital.co.uk" target="_blank">Alienation Digital</a> but unsurprisingly I had forgotten I have already solved this problem as it&#8217;s months since I had to last think about it.</p>
<p>So out comes Google again, I enter my search phrase and I am amazed that the first forum post (which resulted in the path to the solution) was my own post that I wrote while at <a href="http://www.alienationdigital.co.uk" target="_blank">Alienation Digital</a>.</p>
<p>So the moral of the story is to answer your own posts, even if you do end up feeling like you&#8217;re talking to yourself because you the next person your post helps out may be yourself.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chrisshennan.com/2009/08/24/why-you-should-answer-your-own-posts/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Symfony &#8211; Does not have a registered handler</title>
		<link>http://www.chrisshennan.com/2009/08/02/symfony-does-not-have-a-registered-handler/</link>
		<comments>http://www.chrisshennan.com/2009/08/02/symfony-does-not-have-a-registered-handler/#comments</comments>
		<pubDate>Sun, 02 Aug 2009 16:57:01 +0000</pubDate>
		<dc:creator>Christopher Shennan</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Symfony]]></category>
		<category><![CDATA[errors]]></category>
		<category><![CDATA[line digital]]></category>

		<guid isPermaLink="false">http://www.chrisshennan.com/?p=98</guid>
		<description><![CDATA[Last week I was working away in the office at Line Digital on our latest Symfony based project when our project started giving us a strange error similar to:-
Fatal error:  Uncaught exception &#8217;sfConfigurationException&#8217; with message &#8216;Configuration file &#38;quot;/usr/lib/php/symfony/config/config/core_compile.yml&#38;quot; does not have a registered handler.&#8217; in /usr/lib/php/symfony/config/sfConfigCache.class.php:101
Looking into this a little closer we found that [...]]]></description>
			<content:encoded><![CDATA[<p>Last week I was working away in the office at <a title="Line Digital" href="http://www.line.uk.com" target="_blank">Line Digital</a> on our latest Symfony based project when our project started giving us a strange error similar to:-</p>
<blockquote><p>Fatal error:  Uncaught exception &#8217;sfConfigurationException&#8217; with message &#8216;Configuration file &amp;quot;/usr/lib/php/symfony/config/config/core_compile.yml&amp;quot; does not have a registered handler.&#8217; in /usr/lib/php/symfony/config/sfConfigCache.class.php:101</p></blockquote>
<p>Looking into this a little closer we found that the server had ran out of disk space so after making some space and using &#8220;symfony cc&#8221; to clear the cache we thought that this would have resolved the problem, however we continued to get the &#8220;does not havea  registered handler&#8221; message being presented.</p>
<p><span id="more-98"></span>In the end, we had to clear the cache manually with a command similar to:-</p>
<blockquote><p>rm -fr cache/*</p></blockquote>
<p>For some reason this seemed to work fine where as the &#8220;symfony cc&#8221; command didn&#8217;t work therefore the only conclusion that we could come up with is that when the server ran out of disk space it corrupted something in the symfony cache which either is not normally cleared with a &#8220;symfony cc&#8221; and as a result we needed to remove it completely so symfony could re-build it automatically.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.chrisshennan.com/2009/08/02/symfony-does-not-have-a-registered-handler/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
