Snow Leopard upgrade surprise

My work recently ordered our Snow Leopard DVD so we can upgrade our iMacs. I did my usual Time Machine backup and upgraded. I didn’t worry much about compatibility since my personal 13″ MBP has been running SL for a few months now and it had the same apps installed – no problems at all.

After I upgrade my work’s iMac, there were problems. I kept getting errors from my Symantec antivirus (I had to install it, work policy even though it isn’t necessary). I reinstalled it and it warned me to install Rosetta. I thought that would be the “aha” so I installed it. It looks like it fixed that problem, but now my Adobe CS3 apps crashes when I launch them. I Googled and it turns out there is an existing compatibility issue with CS3 and SL. It’s weird though since my MBP runs CS3 without a problem.

So now I got another external firewire hard drive. What I’m going to do is restore a backup that I made in Time Machine before upgrade onto an external hard drive. This way I can make sure that’s a clean copy before formatting and restoring it onto my iMac’s hard drive. This is why I love using Macs. When running into problems, I have several options to restore without losing data – as long as you back up data.

Once this is complete and I’m satisfied with the restored data, I will restore the backup onto the iMac. Then I’ll format the external drive and install a clean copy of SL and migrate my Leopard over to see if it’s SL or just my iMac configurations.

Using PEAR Pager with PHP PDO

This post will be addressing 2 things.

  1. How to use PEAR’s Pager class with PHP PDO
  2. Addressing PDO bug #44639 (http://bugs.php.net/bug.php?id=44639)

Two queries will be used for this task. The first query, you will count the rows of the recordset. The second query is the same as the first but it will have the LIMIT – this is what will be used to display the data on each page.

Let’s say we have the following table.

CREATE TABLE IF NOT EXISTS`blog`
(
`blog_id` int(11) not null auto_increment,
`blog_text` varchar(4000) not null default ”,
PRIMARY KEY `pk_blog_id` (`blog_id`)
) ENGINE=INNODB;

Now we’ll query the database and get the row count using PDO.

<?php

require_once(‘file-with-pdo-db-connection.php’);

$sql = “SELECT * FROM `blog`”;
$stmt = $dbh->prepare($sql);

if ($stmt->execute())
{
// begin pager
require_once(‘Pager/Pager.php’);
$params = array
(
‘totalItems’ => $stmt->rowCount,
‘perPage’ => 10,
‘delta’ => 5,
‘mode’ => ‘Sliding’
);

$pager =& Pager::factory($params);

$links = $pager->getLinks();
echo $links['all'];

// offset setup
list($from, $to) = $pager->getOffsetByPageId();
$from = $from – 1;
$perPage = $params['perPage'];

// 2nd query based on 1st with LIMIT – this will be displaying data per page
$stmt2 = $db->prepare($sql.’ LIMIT :from, :perPage’);

// address bug 44639 – forces the variables to have the property of integer instead of string so no quotes will surround it
$stmt2->bindValue(‘:from’, $from, PDO::PARAM_INT);
$stmt2->bindValue(‘:perPage’, $perPage, PDO::PARAM_INT);
$stmt2->execute();

while ($row_blog = $stmt2->fetch())
{
echo ‘<div>’.$row_blog['blog_text'].’</div>’;
}

}

$dbh = null;

?>

If you don’t use the bindValue, you will get an error in your query. Your second query would look something like this… SELECT * FROM `blog` LIMIT ’0′, ’10′ and the error would occur right after LIMIT. You cannot have quotes surrounding the numbers. It took a few hours of Googling but found the solution.

If you want to read more about PEAR Pager, visit http://pear.php.net/package/Pager/docs.

Here’s a tutorial I found that helped me out a lot – http://www.codediesel.com/php/simple-pagination-in-php/.