Text size +/-

14 Nov 08 _ MySQL Transactions With CakePHP 1.2


By casey
in CakePHP, Casey's Corner

Whew, been a while since I’ve posted something useful.

Hopefully, everyone is aware of MySQL transactions and how useful they can be.  They come in especially handy when you want to save multiple related entries into different tables in your app.  Cake actually already uses this in a behind the scenes way with the Model::saveAll() function, which does some of this for you (you can read more about saving your data with saveAll() here).

But you can easily use Transactions for anything you want to do.

Note: for this to work at all you have to make sure whatever table you’re using transactions with are of the type InnoDB, and not the standard MyISAM type.

ALTER TABLE table_name type=InnoDB;

Ok, in your model, set the variable:

var $transactional = true;

Then, in a function you want to use transactions, call the datasource object:

$db =& ConnectionManager::getDataSource($this->useDbConfig);

Then, before you start interacting with the database, you call:

$db->begin($this);

If your action is successful, run:

$db->commit($this);

Or, if there’s a failure, you can roll back your DB with:

$db->rollback($this);

Note that your DB will automatically rollback if there’s not a commit() command anyway.

In the course of a Model class, the usage of these functions could look something like this:


class YourModel extends AppModel {

var $transactional = true;

function someCoolModelAction()
{

  # Grab DataSource Object #
  $db =& ConnectionManager::getDataSource($this->useDbConfig);

  # Start Transaction #
  $db->begin($this);

  /* SQL or Model Functions for whatever you need to do go here */

  # If your database interaction was successful, then commit the changes to the Database ( I'm assuming there is some boolean
  # variable, $successVar, that describes whether the action was successful or not).

  if ($successVar === true) {
       return $db->commit($this);
  } else {
       # If it wasn't successful, rollback any changes and you're good #
       $db->rollback($this);
       return false;
  }
}

}

As you can see, it’s pretty easy. And cool.

Spread the Word:
  • Slashdot
  • Digg
  • Facebook
  • Reddit
  • del.icio.us
  • StumbleUpon
  • Technorati
  • NewsVine

13 Nov 08 _ Real Life Tutorial: Removing Cream Cheese From Apple’s Tiny Keyboard


By tyler
in BlogTorials, Food & Drink, Just for Fun

No Cream Cheese

We love our tiny, shiny Apple Keyboards (aside from the ridiculous USB placement/depth). We also love eating lunch at our desks. Today happened to be one of those days where lunch somehow ended up on my glorious keyboard. It could have been worse (soup). It could have been better (soft dinner rolls). But it was a bagel with cream cheese. Face down.

It wasn’t pretty, and rather than taking photos of the incident (depressing and poorly lit) I’ll walk you through how to remove a slightly messy substance from a slightly ridiculous keyboard. Read the rest of this entry »

Spread the Word:
  • Slashdot
  • Digg
  • Facebook
  • Reddit
  • del.icio.us
  • StumbleUpon
  • Technorati
  • NewsVine

20 Oct 08 _ WordPress Permalink Redirect (Archive 404)


By Katy
in BlogTorials

After upgrading our AWP Blog to WordPress to 2.6 (we are eagerly awaiting the 2.7 visual transformation, by the way), we noticed in the shuffle our Permalinks got messed up. For example, searching for my post div align top center, which is #1 right now, Google gives us blog.awpny.com/archives/206 (not a permalink). Following that URL used to get us to our 404 Error page. Whoops! Not so great for SEO ratings, not to mention reader frustration!

WordPress doesn’t automatically redirect your old permalinks to the new permalinks, unfortunately. The permalink for the above post is http://blog.awpny.com/2008/03/position-a-div-element-absolute-and-align-it-top-center/. I did a little research. More than a few people have been frustrated with this problem, as you can imagine. I discovered this plugin Permalink Redirect WordPress Plugin. It works perfectly! Thank you Scott Yang’s Playground.

Simply download & install the plugin. Edit the plugin settings (under Settings>Permalink Redirect). For our blog, in the ‘Path pairs to redirect from and to’ box, I used:

[from] /archives/%post_id% [to] /%year%/%monthnum%/%postname%/

And now, Google search results take me to the post, rather than a 404 Error page!

Spread the Word:
  • Slashdot
  • Digg
  • Facebook
  • Reddit
  • del.icio.us
  • StumbleUpon
  • Technorati
  • NewsVine

06 Oct 08 _ Free Stuff: Background Images (grunge/wood)


By tyler
in Design, Freebie

Alright designers and Photoshop friends, come and get it.

We haven’t posted in so long that we felt compelled to give away freebies which can surely be of use to some of you. Here’s a preview of some large grunge/wood background images you can use (download after the jump):

Read the rest of this entry »

Spread the Word:
  • Slashdot
  • Digg
  • Facebook
  • Reddit
  • del.icio.us
  • StumbleUpon
  • Technorati
  • NewsVine

25 Sep 08 _ Songs We Jammed On Last Night


By tyler
in Music

In no particular order:

Creep - Radiohead
Hello, Goodbye - Beatles
Deathly
- Aimee Mann
Karma Police
- Radiohead
I Am The Walrus
- Beatles
AM 180
- Grandaddy
Say It Ain’t So
- Weezer
Reckoner
- Radiohead
Oh Darlin’
- Beatles
Under The Bridge - Red Hot Chili Peppers
I’ve Just Seen A Face - Beatles
The Rip - Portishead

Creep, The Rip, and Oh Darlin’ were, in my opinion, the most excellent, although everything sounded better than it did a month ago (which is about the last time we all played together). Next time we’ll video some of it.

Spread the Word:
  • Slashdot
  • Digg
  • Facebook
  • Reddit
  • del.icio.us
  • StumbleUpon
  • Technorati
  • NewsVine