IIS is evil

Right, so I’m trying to install Apache so I can work on some PHP stuff. It seems I discovered a zombie while I was trying to get it to work. I kept typing http://localhost/, but instead of the “success” page that Apache should give, I get this other page, back when I was using Microsoft’s IIS (Internet Information Services). So, I went back into the IIS folder, which should have been deleted when I uninstalled IIS, and deleted all of those files. When I refreshed the page, I got this:

Honestly. What a stubborn software. It seems that even though I uninstalled, it’s still mysteriously in working condition. Anyone know how to get rid of IIS? Or, how to make Apache the default server?

There’s also something else that I find weird: when I Googled how to uninstall IIS, I got all these web pages about to install it!

Argh!!! Fucking useless!

If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!

October 9th, 2008 | Leave a Comment

Delicious!….hmmmm, yes!!!

This video explains what the title means. Anyway, one of the things I hate about PHP is how redundant the MySQL statements are. Each one is the same thing, but different only by a little bit. Experiencing the same thing? Well, this function I just wrote will help lighten the redundancy!

<?php

function add_mysql_entry($info)
{
if(is_array($info) and sizeof($info) > 0)
{
// Python: mysql_values,mysql_tables = {},{}
$mysql_values = array();
$mysql_tables = array();
if(is_array($info['post']))
{
foreach($info['post'] as $post)
{
// You need single quotes, or else it’s a suntax error.
$mysql_values[] = “‘”.htmlspecialchars($_POST[$post[0]]).”‘”;
$mysql_tables[] = $post[1];
}
}
if(is_array($info['background'])) {
foreach($info['background'] as $background_info)
{
$mysql_values[] = “‘”.$background_info['value'].”‘”;
$mysql_tables[] = $background_info['column'];
}
}
$mysql_values = implode(’,', $mysql_values);
$mysql_tables = implode(’,', $mysql_tables);
$query = mysql_query(”
INSERT
INTO “.$info['table'].”(”.$mysql_tables.”)
VALUES(”.$mysql_values.”)”) or die(mysql_error());
}
}

?>

This function is basically a simple MySQL INSERT statement. It makes it so that you don’t have to declare each $_POST variable, preform all precautions, execute the query, and then make sure that the query did what you wanted it to do. Here’s an example:

<?php

$info = array(
'table' => 'shoes_tb',
'post' => array(
array('add_shoes_name', 'shoe_name'),
array('add_shoes_desc', 'shoe_desc'),
array('add_shoes_price', 'shoe_price')
),
'background' => array(
array('value' => date("d/m/Y"), 'column' => 'shoe_date_added')
)
);
$add_shoe = add_mysql_entry($info);

?>

In this example, there are three $_POST variables that the programmer wants to use: add_shoes_name, add_shoes_desc, and add_shoes_price. He wants insert them in the columns shoe_name, shoe_desc, and shoe_price in the table shoes_tb. Of course, getting something such as the date and not letting the user see it can’t be done through a $_POST variable (other than using the hidden input type). This is where background comes in. The syntax of the $info array is:

<?php

$info = array(
'table' => the MySQL table's name,
'post' => array(
array(input_field_1, column_name_1),
array(input_field_2, column_name_2),
...
array(input_field_n, column_name_n)
),
'background' => array(
array('value' => value_1, 'column' => column_name_1),
array('value' => value_2, 'column' => column_name_2),
...
array('value' => value_n, 'column' => column_name_n)
)
);

?>

All in all, this is function is delicious.

September 1st, 2008 | 2 Comments

One thing you should NOT do with PHP

I know how dangerous it is, but it’s out of habit. What am I talking about? Well, it’s probably one of the most common mistakes a PHP developer/programmer/user will find: an array in a loop. It happens to me all the time, no matter what I’m working with, let it PHP, Python or JavaScript. This is just a reminder to me and anyone who faces this problem: never build an array in a loop! The array will just overwrite itself, and it can be a very well hidden problem. This includes loops and nested loops (loops in loops)… unless you want the array to overwritten. There are instances where the array needs to be overwritten (the mysql_fetch_assoc function is a good example).

This whole post may sound silly, but I suggest you be careful with array building in loops! it won’t cause any major problems (with exceptions), but you will never get the result you want (unless you want to the array to be overwritten, like I said before).

Drieick

August 18th, 2008 | Leave a Comment

Powered by WordPress | Blue Weed by Blog Oh! Blog | Entries (RSS) and Comments (RSS).