Article

Raw SQL from Doctrine Query Object - Revised

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've updated the code to work with Symfony 1.2 - 1.4 and you can find the updated source below:-

function get_raw_sql($query) {
    if(!($query instanceof Doctrine_Query)) {
        throw new sfException('Not an instanse of a Doctrine Query');
    }
 
    $query->limit(0);
    
    if(is_callable(array($query, 'buildSqlQuery'))) {
        $queryString = $query->buildSqlQuery();
        $query_params = $query->getParams();
        $params = $query_params['where'];
    } else {
        $queryString = $query->getSql();
        $params = $query->getParams();
    }
 
    $queryStringParts = split('\?', $queryString);
    $iQC = 0;
 
    $queryString = "";
    
    foreach($params as $param) {
        if(is_numeric($param)) {
            $queryString .= $queryStringParts[$iQC] . $param;
        } elseif(is_bool($param)) {
            $queryString .= $queryStringParts[$iQC] . $param*1;
        } else {
            $queryString .= $queryStringParts[$iQC] . '\'' . $param . '\'';
        }
 
        $iQC++;
   }
   for($iQC;$iQC < count($queryStringParts);$iQC++) {
       $queryString .= $queryStringParts[$iQC];
   }
 
    echo $queryString;
}

I hope that it proves useful.

me.jpeg

I am a web developer specialising in web driven applications using PHP, MySQL, Symfony and Zend and I am currently working for the The Drum in Glasgow, Scotland.

Most days I can be found frantically coding away with EuroDance in my ears and consuming what I hope to be a never ending supply of coffee... happy days!

Want more like this?

Keep up-to-date with latest news from Inside the Agency using any of the following services

Recent articles

Four things that suck about project management

Project management is not a glamorous job.   The better you are, the less you’re noticed: things just hum along nicely, with no major conflicts or serious misunderstandings.  If you’re diligent, skilled, dedicated and competent, someone else will get credit.  The software, application, website or rebuild you so lovingly slaved over will be attributed to your boss, your client, or – if you’re lucky – to your developers or creatives.

In fact, the only time a project manager can rely on getting any real attention is when things go wrong.  A host of complex issues may be present – problematic management behaviour, shifting requirements, lack of necessary cooperation from the wider business, underinvestment in skill or resource – but the blame is ultimately yours.  You’re the project manager.

Read more

“My boss doesn’t get it.” The puzzle of motivation.

Management roles have traditionally focused on issuing assignments and offering rewards.  For much of the industrial age, this worked well.  In the vast majority of situations, people do work harder if they know they’ll get a financial bonus or more recognition.  Primed with 100 years of business advice, managers feel they have the tools they need to get things done, retain their staff and hit their targets.

carrot.jpg

But when they find themselves at the helm of a team of developers, or a mixed team of designers and developers, managers get confused.  The promise of rewards only goes so far.   Sometimes, incentives fail to generate any interest and may even lead to resistance.  Developers who never voice any dissatisfaction put in their notice and move on without any explanation, leaving you scratching your head.  It’s really confusing, and there are no easy answers. 

Read more

The Iron Triangle - How does motivation emphasis create an agency environment?

I remember when I first heard about the Iron Triangle. It sounded sinister, Evil Empire like, and not really something I could embrace in my fluffy idealistic agency brain. Just to be clear in this article I am talking about the Project Management version, not the US political system version… which is sinister and is just like the Evil Empire.

ITA-motivation-illustration-20151120.jpg

Back then I was speaking to my then boss, a man who I credit with opening my eyes to a great deal to how an agency works and, more importantly, how it should work. He was explaining in typically simple eloquence, how he wanted us to set expectation with clients. 

Read more

Advertisement

Digital Ocean

Chris's Reading List

dev-human

dev-human

Things I was unprepared for as a lead developer

I've been a lead developer for 2 years. It has been quite a ride and there were a lot of things I was unprepared for. I've always been a sof... Read more

Moz

Moz

Great SEO Starts with Your Brand

Taking the time to really understand and define your brand allows you to be much more intentional and focused about the way you market your business online. Read more

TechCrunch

TechCrunch

Codie Is A Fast, Rolling Robot Toy That Teaches Kids Progamming Concepts

A robotics company that teaches kids how to code, Codie Labs, took the stage at TechCrunch Disrupt London this afternoon to show off their fast, rolling and.. Read more

KnpUniversity - PHP and Symfony Video Tutorial Screencasts

Fun with Symfony's Console Component

PHP and Symfony Tutorial Screencasts - with free videos, scripts, and code downloads! Read more

JAXenter

Self-promotion is a skill, but is that the skill you're looking for? - JAXenter

Do you want to hire somebody that's good at self-promotion, or are you looking for a certain skill-set? Perhaps you need to shape your job spec differently. Read more

TechCrunch

TechCrunch

When Crowdfunding Fails The Backers Are Left With No Way Out

A few years ago an enterprising programmer dug through Kickstarter's data to figure out how many failed projects there really were. Thanks to a trick in the.. Read more