Archive for August, 2008

Extremely helpful Microsoft Silverlight warning

August 14th, 2008

I had an old version of MS Silverlight installed on my machine. This is Microsoft’s attempt to compete with Adobe’s (formerly Macromedia’s) Flash.  Way to go guys – that train left the station in, oh, I don’t know… 1996?

Bottom line is that nobody is really using Silverlight – besides MS’s attempts to force it down your throat on their own website and through some strategic marketing moves (ie. with NBC Olympics online coverage).  Plus, the sites that do offer streaming media via Silverlight were thankfully not stupid enough to make that your only option.  I haven’t been to a site yet that doesn’t offer me the same feature with Flash Video for example.

Anyway – there is a newer version of Silverlight out -  so when I visit a page that is trying to stream content via the Silverlight plugin, I get this error:

How awesome is that?  Did MS really think I could click the link and get to the update page? No – maybe I was expected remember that URL or write it down so that I could quickly download the newer version and get to my content.

How classic is that?!?!

Why doesn’t Lindsey Graham just go ahead and claim the (D)?

August 14th, 2008

What a waste of a senate seat.  The goofy, nil-brained senator from South Carolina has once again (shock! surprise!) swerved to the left in an effort to advance his personal interests.

And so, last Friday, in stumbled Sens. Lindsey Graham, John Thune, Saxby Chambliss, Bob Corker and Johnny Isakson — alongside five Senate Democrats. This “Gang of 10″ announced a “sweeping” and “bipartisan” energy plan to break Washington’s energy “stalemate.” What they did was throw every vulnerable Democrat, and Mr. Obama, a life preserver.

Here are the dirty details from the WSJ.

Way to go Lindz, you really know what the people want.

How to use PHP’s sprintf() on a MySQL query utilizing DATE_FORMAT()

August 2nd, 2008

It is good practice (common sense?) to filter your SQL queries.  One way to accomplish this in PHP is to utilize a function like sprintf() which will format a given string and integrate values into the string using conversion specifications which are passed in as arguments to the function.  In plain english, that means you can call the function, pass in a value and require that value to be a integer, for example.  If the value you passed in is a string, roughly speaking, it will sanitize your output.

An example in a MySQL query would be this.

<?php
// build our sql string.
$sql = "SELECT * FROM table WHERE field=%d";
$sqlf = sprintf( $sql, $somevalue );
$db->query($sqlf);
?>

As you can see, you can designate where the substitution will take place in the $sql string. That’s easy. But what happens if you need to use MySQL’s DATE_FORMAT() function? It requires that you pass in arguments to define its output (ie. Day as a word, day as a date, month as a number, etc).

<?php
// build our sql string.
$sql = "SELECT DATE_FORMAT( %b %M %d %Y, some_date_field ) as myDate FROM table WHERE field=%d";
$sqlf = sprintf( $sql, $somevalue );
$db->query($sqlf);
?>

This will fail. sprintf() will complain because you haven’t passed in enough arguments. It is expecting 5 values as part of the call, instead of just the one that you are trying to replace (in the SQL WHERE clause).

So what’s the solution? You have to “comment-out” the % that aren’t part of your sprintf() substitution. You can do this by putting another % in front of the ‘%’ symbols in the DATE_FORMAT() function. This deems them as a literal percent-sign instead of the start of another sprintf() “variable”.

<?php
// build our sql string.
$sql = "SELECT DATE_FORMAT( %%b %%M %%d %%Y, some_date_field ) as myDate FROM table WHERE field=%d";
$sqlf = sprintf( $sql, $somevalue );
$db->query($sqlf);

Hope that helps!

I may need protection from myself…

August 1st, 2008

Today, I spent almost an hour staring at this line of code:
if ($this->dbi->affectedRows>0) {

Oh – and it would be helpful for you to know that affectedRows is a method in a database class.

A method, that’s right.  Unfortunately for me, method is not spelled, v-a-r-i-a-b-l-e.

Amazing what two little ( ) can do to your stress level.
if ($this->dbi->affectedRows()>0) {