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!
Let me start by telling you about my potential bias: I have long wanted a good linux dock. AWN simply doesn’t cut it. It’s very buggy, crash prone, and the interface is just very odd to work with, from my personal experience. Cairo dock is another option, but it’s even buggier than AWN, not to mention the fact that the preferences window is the most insane “design”, if one could call it a design, I’ve ever seen.
After trying both of these options on numerous occasions, I reserved myself to just using the simple gnome-panel tasklist applet. It works, it lets me see what I have open, and it’s not extremely buggy.
That is, of course, until I was in the #ubuntu-offtopic channel the other day, and “overheard” Amaranth and DBO talking about a new dock.
I started reading my backlog, then once I was caught up I started talking to DBO. What he was describing was basically the perfect dock. The icon zoom worked and worked properly, it supported reading the windows correctly so there weren’t the bugs typically associated with docks, and, here’s the kicker, it integrates with one of my favorite productivity applications, GNOME Do. What’s more, it had intelligent window grouping and selection, to get you to the proper window quickly.
So I started talking to DBO, and he told me that I wouldn’t be able to run it in Hardy because it doesn’t support Mono 2.0. My heart was crushed.
However, a few days later, I was back in #gnome-do, and DBO told me that I might be able to run it in Hardy with a custom Mono. What followed was a bunch of testing, trying, and eventually building. After adding in a custom repo and installing extra mono packages, and replacing my /usr/lib/mono/2.0/gmcs.exe with a custom one, I was able to use it.
I quickly finished installing it and loaded it up, then began to use it. The first thing I noticed was that it integrated itself as gnome-do, not just added upon it. Now, when I summon do, it brings it up down as my dock, which only makes things sexier:
It also fully implements grouped windows (though, at first this was giving me issues, DBO soon resolved the issue, thanks =D). You can control the group, or individual ones. Clicking on the main icon for a group is also intelligent. If something demands attention, then it goes to that window, otherwise there are other rules to help ensure you get to the window you want.
It maintains all the old functionality:
While updating some of the plugins (for instance changing Twitter to Microblogging to add Identi.ca support):
And it also completely implements dual-monitors, for those of you who use them:
That’s not to say it’s without hitches. I’ve found that it doesn’t seem to like /usr/share/applications/lynx.desktop, because of (I can only assume) the Russian characters. I’ve deleted this file to get it to work.
Also, it doesn’t yet have support for workspaces. The icons you see are the icons from all your workspaces. I keep prodding DBO about that, hopefully he’ll get around to it.
I have some issues with it at work, the performance is really bad, but that’s not saying much because I’m running an 8600GT which seems to have been affected by the powermizer bug.
Lastly, since I’m using 4 monitors, with 2 screens, the “Switch monitors” button gets a little confused, trying to flip to the third monitor in my first screen, which doesn’t exist. As far as I know, DBO is currently working on this, or will be in the near future.
Here are some notes for those of you who want to try it out:
If you want to run it, in Hardy at least, you’ll need a custom mono. First, add the following to your /etc/apt/sources.list:
# custom mono
deb http://ppa.launchpad.net/directhex/ubuntu hardy main
When I first ran it, I needed ot put in my own gmcs.exe, but with some updates by RAOF, it now automatically does that for you, so you don’t need to worry about doing it.
Once you’re done, check out gnome-do and do-plugins by cd’ing to a working directory and executing the following 2 commands:
bzr branch lp:do
bzr branch lp:do-plugins
Once done, go into each and install them:
./autogen.sh
make
sudo make install
Once you’re done, go and delete ~/.local/share/gnome-do/plugins* to remove your old plugins and configuration, if you already have gnome-do.
Finally, run gnome-do, then go to the Appearence tab and change the theme to docky. Voila! You have the greatest dock and productivity bar ever!
Thanks for all the help djsiegel, RAOF, DBO, and everybody else who helped!
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
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.
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!