Archive for the ‘Technology’ Category
Still looking for fast web development techniques
I’ve been developing web sites for almost 10 years now. I’m still in search of a way to develop faster. I find myself doing things over and over again.
I use PHP as the programming language to develop the web apps with MySQL database. I started to look for different frameworks – but most use MVC and I don’t have time to learn it.
Some have suggested to do validation using MySQL. This helps a bit so I don’t have to write more PHP code to validate whether or not the record exists, foreign key constraints, etc. Plus it really is good practice to have these in place in the database layer.
Next I looked in to template engines to help with the layout of the site. It does help quite a bit but I’m still left with a lot of PHP code. I use Dreamweaver to write code and I used to use its automated code writing but I found it too messy and inefficient. Now I only use it because the FTP client is built in, has a file checkout system and in CS5 it can read included files so I have easy access to them. The error check is nice too. It catches many syntax errors right away. It can read used variables and be a part of the autocomplete feature.
I tried using existing systems like CMS or blogs (Joomla and WordPress). I figured I can create add-ons on top of an existing system. Joomla uses the MVC framework. WordPress on the other hand is easier to figure out how to build on top of it. Plus their documentation is really easy to follow. One of the limitations I found is the lack of access levels. Another is the pre-existing environment may not fit with a project since it’s so customized – better to be built from the ground up.
I’ve been peeking into the .NET framework off and on. I don’t primarily use Windows at all. I’m mostly on a Mac or using some sort of Linux flavor. I do have Windows7 running virtually on my MBP and iMac so I can play with it. I have played with Visual Studio and it felt easy to use plus it seemed to make developing quick. The drawbacks I’ve found are Windows hosting is more expensive than Linux hosting, IDEs are expensive and run mostly on Windows OS, and I don’t like creating online applications that can potentially only work with Internet Explorer (does not support web standards and only available on Windows OS).
Rails looks promising with the DRY (don’t repeat yourself) approach. I’ve tried to look into it and even bought some books and watched some screencasts. It’s a great language but I can’t seem to understand how to authenticate/authorize different users. They have many different plugins that I can use but each one uses their own way of doing it.
I guess I’ll keep looking. Either I’ll find time to learn MVC framework, get better at Rails, or someone will develop a new platform to speed up web development.
Connect to MSSQL 2005 using PHP
Here’s a couple of quick tips to connecting to a MSSQL 2005 server using PHP on a Windows webserver. You will need to enable the php_mssql.dll in your php.ini file.
Here’s the code to connect to the server.
<?php
$conn = mssql_connect(‘my_server’, ‘db_username’, ‘db_password’);
if (!$conn) { die(‘ERROR: Unable to connect to the database.’); }
mssql_select_db(‘database_name’);?>
Here is a helpful function I found that will help escape strings. I found this at http://stackoverflow.com/questions/574805/how-to-escape-strings-in-mssql-using-php.
<?php
function ms_escape_string($data) {
//if ( !isset($data) or empty($data) ) return ”;
if ( !isset($data) or empty($data) ) return “””; // modified to handle empty $data
if ( is_numeric($data) ) return $data;$non_displayables = array(
‘/%0[0-8bcef]/’, // url encoded 00-08, 11, 12, 14, 15
‘/%1[0-9a-f]/’, // url encoded 16-31
‘/[\x00-\x08]/’, // 00-08
‘/\x0b/’, // 11
‘/\x0c/’, // 12
‘/[\x0e-\x1f]/’ // 14-31
);
foreach ( $non_displayables as $regex )
$data = preg_replace( $regex, ”, $data );
$data = str_replace(“‘”, “””, $data );
//return $data;
return “‘”.$data.”‘”; // modified to handle empty $data
}?>
Here is a sample query to the database.
<?php
$id = ms_escape_string($_GET['id']); // escape variable
$sql = ‘SELECT id FROM table_name WHERE id=’.$id.”;
$rs = mssql_query($sql);if (!$rs)
{
echo ‘ERROR: Unable to get records. ‘.mssql_get_last_message(); // equivalent to mysql_error()
}else{
while ($row = mssql_fetch_assoc($rs))
{
echo ‘The id = ‘.$row['id'].’<br />’;
}
}?>
Another thing I learned from the article is the equivalent of “mysql_insert_id()”. It is “SELECT @@IDENTITY”. To handle dates and make them friendly to PHP use CONVERT(VARCHAR, [date], 20). This will display it as if you are using date(‘Y-m-d H:i:s) – 24 hour format. So an example would be…
SELECT CONVERT(VARCHAR, getdate(), 20) AS now
I tried to use PDO but was having a hard time getting it to work. I kept getting errors that had something to do with functions. I searched for solutions and tried them but none worked for me. Also, the rowCount() will always return less than or equal to 0.
I had trouble on both sides PHP and Microsoft. This seems to be the best solution that works for me. Hope it helps others.
Artisteer 2 and Dreamweaver CS5
I’ve been trying out the demo for Artisteer 2 and it’s great. Creating templates for popular CMS softwares such as WordPress, Joomla, and Drupal have never been easier. I’ve done some playing around with manually creating a WordPress template and it’s not too bad. The WordPress documentation is fairly easy to follow. But doing it in Artisteer is a lot quicker. There’s 2 versions of the software, a home/academic edition that will create WordPress templates for $50 and a standard edition that will allow you to create templates for the other CMS (Joomla, Drupal, etc) for $130. So far I only need the home edition since I use WordPress but at work we also use Joomla. I don’t normally create the layouts at work so I’m hesitating to buy the home edition. I have sent them an email to see if there’s an upgrade path from home to standard and the cost. My work will not pay for the software and if they do, it will take such a long time to get since they only purchase things through purchase orders (sigh).
Now I’ve been curious about Dreamweaver CS5. I’m currently using CS3 with Espresso. I rarely use Dreamweaver’s auto coding – it’s too bulky. I like coding by hand. Espresso is great for that and it’s lightweight and fast. It just doesn’t have the design view tab like Dreamweaver does. Adobe also has a student/teacher version of the software for only $150. I’m downloading a trial version now and will check it out. I’m curious about the CMS code “sniffer” that they have.
Deleting ._ files in Windows
At work we use iMacs for workstations but Windows for servers. There are some nuisance when sending files from OS X to Windows. Filename lengths, network connections, hidden files – just to name a few.
In OS X, there are hidden files that start with ._ which become visible when viewed in Windows. It’s usually not a problem. It becomes a problem when you are working with Joomla. If you download and unzip Joomla, then transfer the files to a Windows machine, you will get a ._ for each file and folder. This bad because in the Joomla system, there is an XML file for each components, modules, plugins, themes, etc that describes it. There is also a list of files in that XML file. You will probably get errors in the Joomla admin interface because of those ._ files.
Here’s the command to get rid of them in Windows. Open up your command prompt and enter the following command…
del /A:H /S /Q [location] ._*
The del command means delete. The A switch selects files based on an attribute. The H means hidden attribute. The S switch is used to search subdirectories within the [location]. The Q switch is quite mode and is optional. [location] is obvious so replace this with the path of where you want to do the deleting. Finally, the ._* means files that start with ._ and the * is a wildcard.
Make sure you check to make sure there are no files that begin with ._ that you need.
Our new iPads
I stood in line in front of Best Buy to try and get myself and Abby an iPad. I had already planned on getting the 32GB model while she gets the 16GB. Why didn’t I pre-order it or go to Apple you ask? Because of Best Buy’s reward zone points plus Best Buy has no interest for 18 months, that’s why. There were about 20 people in line right before they opened. The manager came out and said that they normally handed out tickets but for the amount of people in line, they will have plenty – plus another truck arrived minutes before with more. So much for worrying about getting one but I was excited to get ours so I didn’t mind standing in line for 30 minutes. I was in 4th and the guy in front said he has been there for 3 hours haha.
Anyway, we got our iPads and it’s better than I thought it would be. First off, I have a 13″ Macbook Pro, a Compaq Mini netbook, a HTC MyTouch 3G phone – so why would I want or need an iPad? What can I do with it that I can’t already do now with my portable devices? And finally, many have made fun of the iPad asking “What is it for?”. Well here is how I look at an iPad device and how I would use it.
- Instant start up. The iPad powers on with a touch of a button and is useable right away. No waiting for boot up. I do leave my Macbook Pro on and sleeping most of the time but the battery drains – slowly but surely.
- Size. It is the right size for what it can do. It’s smaller than my laptop and netbook (weight) and it can do the common things like surf on the internet, check emails, read files, and some word processing – I say some because of the virtual keyboard, it can get tiring typing on it. You can however use a bluetooth keyboard if you don’t mind carrying another item. It is larger than my phone but my browsing experience is better on the iPad because it’s larger.
- iPhone OS. I just love the iPhone OS. I had the first gen iPod touch and iPhone 3G and I missed the user experience after I got rid of them. The functionality and ease of use, no one has been able to match – although Google Android is getting there. But I’m a Mac user and I guess I expect to have a similar experience on other devices other than my computers.
- Apps and games. Similar to the iPhone OS experience, there aren’t many apps or games you can use/play on mobile devices that give the same experience as they do in the iPhone OS.
- Ebook reader. This is one that I didn’t care too much for but I’m glad it’s there. There are other ebook readers out there like the Amazon’s Kindle that do a good job. But the iPad not only can do what other ebook readers can do, it can do more , it can be more.
- Portable video player. It is an excellent portable video player. You can play videos purchased from iTunes, videos encoded with Handbrake or other software, portable formats that come free when you buy the Blu-ray or DVD version, online videos from apps created by ABC network, Netflix (subscription fee), Youtube, etc. And I’m betting more to come, it’s just a great platform for developers to develop on.
- Battery life. It last longer than my other portable devices even when watching video.
There’s so many things you can do with the iPad even if you already have other portable devices. Many compare it to the iPhone and iPod touch – but just a bigger version. It’s more than that. Yes it’s bigger so your internet surfing experience is better – close to being on a computer… still no Flash support. With HTML5 standards coming soon, this shouldn’t be a problem in the future. Also, the iPad comes with a more powerful processor. Typing on it is a lot more smoother than my iPhone 3G. Apps and games load quicker and more responsive.
I definitely recommend getting one.