StuRReaL

12th December 2006

UTF-8 viewing source bug in Internet Explorer

Today I have come across another interesting bug in IE6/7. This bug relates to the user not being able to view the page source when the charset is set to UTF-8 and the url contains a hyphen.

When you have the charset set to UTF-8 and you happen to be using mod-rewrite where the bit after the domain has a hyphen in it, try viewing the page source. You'll notice it doesn't work now refresh that page and it works. Strange indeed.

So with the meta tag set to:

<html>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

</html>

http://www.somedomain.com/some-thing-here/
The above type of URL doesn't work when the charset is UTF-8.

NB: After some more digging I've come to realise that its down to notepad not being able to understand UTF-8 but what I don't get is how it manages to open it on the second attempt

http://www.somedomain.com/somethinghere/
this particular URL works perfectly.

Now change the charset to iso-8859-1 and it all works perfectly.

<html>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />

</html>

This bug doesn't happen in any other browsers i've tried.

14th November 2006

MySQLi Prepared statement stupidity

Today I decided that it would be great to improve my MySQLi abstraction class by adding support for prepared queries.

Now what I really want to know is, what was going through the developers minds when they devised the mysqli_stmt functions I mean really, they are horrendous, to explain this lets take for example the PostgreSQL functions for preparing an SQL statement.


<?php

$sqlQuery = "SELECT * FROM my_table WHERE id= $1";
pg_prepare($dBConnection, $sqlQuery);
$results = pg_execute($dBConnection, "you can name your query if you like", $arrayOfParams);

?>

I think you'll agree thats really easy. Now the MySQLi way.


<?php

$sqlQuery = "SELECT * FROM my_table WHERE id= ?";
$stmt = mysqli_prepare($dBConnection, $sqlQuery);
mysqli_stmt_bind_param($stmt, 'i', $id);
mysqli_stmt_execute($stmt);
mysqli_stmt_store_result($stmt);

?>

Why? just why? To be able to make this generic enough I need to use eval() on the mysqli_stmt_bind_param() as it won't take an array of parameters, also it can't figure out the type of variable or the type required by the column in the DB so you need to tell it. So here is my solution.


<?php

public function PreparedQuery($sql, $paramsArray)
{
    if ($stmt = mysqli_prepare($this->GetDBLink(), $sql))
    {
        $types = '';
        $vars = '';
        $numParams = count($paramsArray);
        
        //Checks for type as it binds array or params
        for($i = 0; $i < $numParams; $i++)

        {
            //figure out what type the variable is
            $types .= $this->Type($paramsArray[$i]);

            //build a string of variables to bind
            $vars .= '$paramsArray[' . $i . '], ';
        }    

        $bindings = 'mysqli_stmt_bind_param($stmt, "' . $types . '", ' . rtrim($vars, " ,") . ');';
        
        eval($bindings);
        mysqli_stmt_execute($stmt);
        mysqli_stmt_store_result($stmt);
        
        return new MysqliPreparedResult($this->GetDBLink(), $stmt);
    }
}

?>

Now the retardedness doesn't end there, because, I need a second Results class to cope with the fact I need fetch the data in a completely different way. Again like the mysqli_stmt_bind_param() you need to bind the results to a bunch of variables and again you can't bind to an array WHY? WHY DO THIS?

So again its an eval() job to get the data out in the way you'd usually get data with the mysqli_fetch_assoc() function. Heres the solution which I adapted slightly from someones code in the PHP manual.


<?php

private function PrepareResultsArray()
{
    $results = mysqli_stmt_result_metadata($this->result);
    
    $bindResult = 'mysqli_bind_result($this->result, ';
    while ($field = mysqli_fetch_field($results))
    {
        $bindResult .= '$this->ResultRow["' . $field->name . '"],';
    }
    $bindResult = rtrim($bindResult, ' ,') . ');';
    
    //echo $bindResult;
    
    eval($bindResult);
}
?>

Once this is done I can grab rows like normal :) by using an adapted version of my GetRow() method. The end result is still a nice associative array database fields. I'll post the code later once i've spent some time testing it fully.

30th August 2006

Vista Pre-RC1

Well i've just installed it on my aging 1.6Ghz Pentium M laptop with 1Gb of ram and a Radeon9600 Pro. My first thoughts when installing it, and i'm thinking wow we're back to the same number of reboots as Windows98 needed to install; well thats a step in the right direction, it amazes me when you can install linux reboot and you boot into your new linux install why can't Microsoft manage that?

Next point I have to say I like the spangly interface aero glass is nice, but its a bit laggy for saying its hardware rendered and not actually doing a great deal other rendering a couple of windows with transparency, I just don't understand there I mean Half-Life 2 runs like a dream on my laptop why doesn't my desktop?

Media Centre.... Hmmmm why? I don't want that, I have no use for it! why can't I remove it I mean Vista is nearly an 8Gb install WindowsXP is only 1.5Gb where does the extra 6.5Gb of extra features come from? Sorry to all those people who love media centre, I'm sorry I don't have a use for it my machine is used for working on and a few games, so why do I need that installed when I have no use for it? It would just be better if microsoft added all these features but allowed the user to remove them or I get a bare bones install that I can add the extra bits and bobs as I see fit.

It would just be nice if I was given the option to remove the stuff I don't need I used to be able to with Windows 95 (ok so Win95 never really worked correctly but I least I had a choice of how it wasn't to work)

Well it seems I've been very negative and I have, there were some many great things to look forward to then they got removed :( so I'm not sure what my extortionate licence fee is going to get me if I decide to buy it I think I might stick with XP x64 as it works.

4th August 2006

Wow two posts in so many days

Well I thought that I should post about my latest little pet project, well its more of a side project as some other projects depend on this one. I've basically been working on a little app in C# which will be ported to Java and run as an applet to upload files via HTTP, now I here you all say "but there's lots of those" and yes you'd all be right but this one is different.

My nice little uploading app gets around the annoying memory limits of PHP (maximum post size, PHP's own memory limit and the file upload limit), now I know that you can alter those, but it still doesn't help you upload multi gigabyte files. There is also the HTTP PUT method but that involves server tinkering and I wanted this to be as zero config as possible. I get around this be dividing a file into 2mb chunks saving them in a directory and concatenating them when its all done. I haven't found any that do it properly and that don't cost a fortune so I've written my own.

I'm going to sell it so people can use it but it will be for a tiny amount but I'll think about that later, right now I have to learn java and fix some of the unhandled exceptions I'm getting, doh! oh and does anyone know how to pass data between threads?

2nd August 2006

Damn Damn Damn and Damn

Well the good news is the my sites back, the bad news is its an old version. So I have to do most of it again, but I'm on a new host, so it all isn't bad. Now I just need to finish my new admin panel and upgrade the looks a bit and I might finished. I'm also gonna put some content and post stuff more often believe it or not.