MySQL Duplicate Entry, But Not Really

I chased an interesting bug today. MySQL was complaining about “Integrity constraint violation: 1062 Duplicate entry”. I had all the necessary safeguards in my code to prevent duplicates in tha column. I gave up on logic and simply dumped the contents of the problematic column for every record. I found that there was a record with…

Read More

Converting a Joined Resultset Into a Hierarchy

I needed nested resultsets in some projects. I’ve seen a lot of StackOverflow chatter which essentially pointed people towards Doctrine or Propel ORMs, which was overkill when you didn’t want mapping or even model classes. I built a very small function that will transform joined results into a hierarchy. This avoids using heavy ORMs if you just…

Read More

Reduce number of queries

Customers often call me because their site is slow. One of the most common problems I found was a high number of queries that get executed for every single page hit. When I say a lot, I mean sometimes more than 1000 queries for a single page. This is often the case with a CMS…

Read More

Profiling MySQL Queries – Part 1

You website is slow. You suspect MySQL queries are slow, but don’t know where to begin. This article, aimed at intermediate developers, will present my methodology and serve as a starting point for first-timers. I won’t go in-depth, only cover some of the basics…

Read More

doctrine:insert-sql for MAMP users

One of my computers has MAMP installed. I was trying to build a database schema from a YAML file. When time came to insert the SQL using… >php symfony doctrine:insert-sql the following error message appeared: >Couldn’t locate driver named mysql MySQL worked fine on this computer for many years so a missing driver was out…

Read More