WARNING: Your browser, IE6, released in 2001 and superseded by IE7 in 2006, is out of date. I advise that you either upgrade to IE7 or switch to a more standards-compliant browser.

Archive for the ‘Development’ Category.

PHP Database Library

For a while now, I’ve been working on a PHP DB wrapper class. The whole point of it is to make writing the same old queries over and over again a little bit easier to manage. I’ve noticed that I haven’t had to edit it over the past few months, and I’ve implemented it at work without issue on many occasions, so I figure it’s time to share it with the world.

To use it, first create an instance of the object:

$db = new db("user", "pass", "db", "host");

And once you have it, you can perform various types of queries.

For selects that will return multiple rows, use the following syntax:

$rows = $db->q("SELECT * FROM tbSomeTable;");

$rows will then either be false (which means the record had an error or returned 0 records) or an array of row objects:

foreach($rows as $row){
    print($row->someField);
}

For single-row queries (such as those with LIMIT 1 or using a COUNT or similar function), use sq:

$row = $db->sq("SELECT COUNT(*) AS intCount FROM tbSomeTable;");

$row is then an object representing a single row of the resultset. If the query returns multiple rows, only the first row is used.

For insert, update, delete, and other queries, $db->q is used.

An advantage to my wrapper is the printf-like auto-escaping, allowing you to easily use user input:

$rows = $db->q("SELECT * FROM tbUsers WHERE User='%s' AND Pass='%s';", $_POST["user"], $_POST["pass"]);

The %s are then replaced with the corresponding argument and automatically stripped using mysqli’s strip function.

Here’s a short snippet tying everything together showing how quick and easy it is to write a DB resultset iteration:
if(($rows = $db->q("SELECT * FROM tbUsers WHERE intUserType='%s';", $_GET["intUserType"])) !== false){
    foreach($rows as $row){
        print($row->strUsername . “<br />”);
    }
}else{
    print(”No records found!”);
}

Debugging can be achieved via $db->messages();

It also has support for transactions (commit, rollback), documented in the readme

If you want to give it a try, you can download it here

If you have any questions or suggestions, leave them in my comments!

Life Updates and New Tech

Well, I’m back here again. Overall, things are going well for me. I picked up a bike, and my plan is to ride is as much as possible so by summer I’ll be able to ride it to work. I rode for 5 miles the other day, and it’s 10 miles to work. I’d like to get my speed to double what I went so it takes me the same amount of time.

I changed my mind on that desk. I decided that with all the transportation, tool rental, gas, etc., that building my own desk would be as expensive as just buying one and when I buy one it’ll be better anyway. So I did just that, you can see some pictures here. I also bought myself a new widescreen 22″ monitor, very nice, and bought another smaller 17″ off my friend. You can see all my new monitors in the last picture in that album. Overall, it’s a very comfortable and awesome setup now.

I’m using compiz 0.7.8 built from git, and that works just fine for 4 monitors. What I did was split them into 2 groups of 2 monitors each. Each group sits on a video card and runs an X screen with TwinView. I can’t move windows between each set of screens (the left 2 are attached, and so are the right 2), but I’ve found that I actually prefer that. I have the far right monitor dedicated to widgets and monitoring applications, then the next is usually for movies being the only CRT, then the left two are for my active applications.

I also added yet another drive to my system today, a 1TB drive this time. That brings the total to 5 drives, totalling 2.5TB storage. All 5 SATA, and I can’t fit anymore in now =P

My Hard Drives

I got hosting from tonyyarusso for a pretty good price, so you might see some progress finally being made on this thing since I can actually run it stable. The blog is currently being run off of it.

I’ve written a pretty cool application lately. I used Python, PHP, MySQL, and JavaScript to write an application that basically scans my entire music directory, loads the ID3 tags into the database, then lets me search and browse all my music and add it to a playlist. From there, I have a javascript MP3 player I wrote to play my playlist back. This is very useful for while I’m at work, and once I figure out how to get Python libraries installed on the server I’ll begin putting some of my music up here.

A screenshot of my player

I’ve added a twitter updates and blip.fm updates widget to the side of my blog. I made sure that the blip.fm player can be hidden, and when you hdie it it stays hidden.

At work, we’re planning on Nerf wars. I’m going to order a Maverick. It’s exciting. We’re all moving into cubicles. That’s not. It feels like a demotion, going from an office to a cubicle. Even some of the interns have offices -_- Oh well, I’ll just keep waiting until January when we supposedly get raises. Pay me enough and I’ll be a lot more willing to get screwed in other areas.

Lastly, I want to blog-whore my friend snuxoll. He may be extremely opinionated at times, but a lot of the time he’s spot on and usually pretty knowledgeable about things. Give him a read!

Well, that’s it for now. Signing off!

Updates

I’m currently working on a rapid development framework, which combines the MVC pattern, a Data Object, a DB Wrapper, AJAX helpers, and many other things implemented as helpers, rather than as the typical framework approach, hindering development more than speeding things up. I like to have more control over my apps than CakePHP offers, so I’ve taken it upon myself to write my own alternative. It’s certainly not as refined, but that’ll just take time. Also, documentation will actually be beneficial for people unlike CakePHP.

I’m in my new apartment, all set up except for a few things. I’m going to be buying some wood and building a desk for my living room, and I’ve ordered some LEDs and with the help of my friend Mike we’re gonna set up my living room with some low-power bright LEDs. I’m thinking of putting them up behind some wax paper, to sort of diffuse the light and soften it. Next up is to find somebody who can paint, especially on a large scale, because I’d like to be able to have a sweet mural/painting on my wall.

My friend Josh and I have decided to use Adobe AIR to develop our own todo list with built in timer to keep track of hours spent on projects at work.

I’ve also decided I’m going to build my own desk, and I’ve already got the designs. It’s going to be 30 inches deep, and about 4 feet wide. The back half of the desk will have an elevated platform for 4 monitors to sit on.

Lastly, I’ve begun twittering regularly, so check me out and follow me if you like: http://twitter.com/dmsuperman

Alright, I’m off for now but I’ll be coming back soon with more updates, and eventually the framework will be posted for public use.

Twitter