Author Archive

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.

  • Share/Bookmark

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.

  • Share/Bookmark

2010 NBA Finals Bet Video

My cousin Ronald and I had a bet on the 2010 NBA Finals. The loser buys the winner a swingman jersey, wear it while making a video and read off a speech prepared by the winner. I lost but he didn’t want to write a speech is I had to make up what I had to say.

Enjoy the video. I know a lot of old friends who are Laker fans will.

  • Share/Bookmark

Form validation that contains arrays from checkboxes and radio buttons with jQuery

I’m using the jQuery plugin from http://bassistance.de/jquery-plugins/jquery-plugin-validation. The plugin is greate. I did run into a problem with arrays. Say your form has a group of checkboxes or radio buttons and their names are checkbox or radio. To have them be in the same group, their names have to be the same and to process it using PHP as post variables you have to throw them in arrays. So in the form their names will be checkbox[] or radio[].

In your validation you probably have something like

rules: {
checkbox: { required: true },
radio: { required: true }
}

The element name no longer matches because in your form they are checkbox[] and radio[] while in your javascript they are checkbox and radio. To solve this, use quotes and add the []. So here’s a quick example.

<script type=”text/javascript”>
$(document).ready(function()
{
$(‘#form1′).validate({
rules: {
“checkbox[]“: { required: true },
“radio[]: { required: true }
}
});
});
</script>

<form id=”form1″>
<input name=”checkbox[]” type=”checkbox” value=”checkbox1″ /> checkbox 1
<input name=”checkbox[]” type=”checkbox” value=”checkbox2″ /> checkbox 2

<input name=”radio[]” type=”radio” value=”radio1″ checked=”checked” />radio  1
<input name=”radio[]” type=”radio” value=”radio2″ />radio  2
</form>

The radio button is an overkill since you normally have 1 checked by default unless you forget. The plugin is great so if you haven’t checked it out, I highly recommend it.

  • Share/Bookmark

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.

  • Share/Bookmark
Categories