Archive for PHP

dojo.wine() - another dojo.beer() just with wine

Together with Mayflower, we from uxebu are organizing the next dojo-event, this time it’s dojo.wine().
This time it will be in the Mayflower office in Würzburg (Germany) and we hope to see all people interested in JavaScript, AJAX and all the modern web stuff there.
As you can see in the following video we were a good number of people and had nice food!

dojo.beer(2) from Tobias von Klipstein on Vimeo.

Comments (2)

dojo.beer(2)

We from uxebu have organized the second dojo.beer and are happy to have won Mayflower to jump in sponsoring the location here in Munich, Germany. On friday the 5th december we will warm up with some dinner and some beer in some place here in Munich. The real thing will be on the 6th at the Mayflower office, doors will be opened at 12:00 and we are hoping for a lot of talks from various people, to see how the are using dojo and we are also hoping to have interesting talks providing some useful input and may be even new stuff to learn. Bring your laptop and let’s hack away. If you have something special you need to have solved there will be someone who can help, for sure. From beginners to experts everyone is welcome. You don’t know nothing about dojo yet, but are interested you are right at the dojo.beer. You are a long time dojo user and want to dive into the depths of dojo, you are also perfect at the dojo.beer. So let’s have a great time and join us at the dojo.beer().

Some selected topics will (hopefully) be: functional programming with dojo, i18n, dojango, dojo build, dojo+Adobe AIR, deft - the dojo experimental flex technology, dojo and Zend Framework and many more.

Find all the details here dojo.beer.mixxt.de.

Comments (6)

Dojo + Zend Framework

Yeah, this is really really good news, for both worlds. I was following Zend Framework loosely but from a lot of friends in this scene I have heard that it is the rising star and quasi industry standard of PHP frameworks. And now the logical next step to join forces with dojo is just right. For those that have doubts, you can use any other JavaScript toolkit with it too, but why would you want :-).
Looking forward into the great future of server and client interaction!

Comments (1)

Python is still awesome

Just because I just came across it while optimizing some old code, I have to mention this.
I have the following list of dictionaries (array or hash-arrays in other words) and I want to sum up the values of one of the items of the dictionary.

In python I do this


    d = [{'value':1, 'title':'one'}, {'value':2}, {'value':3},
         {'value':4, 'title':'four'}, ]
    s = sum([i['value'] for i in d])

In PHP I would have done this (I guess)


    function extract_value($r) {
        return $r['value'];
    }
    $d = array(array('value'=>1, 'title'=>'one'), array('value'=>2),
               array('value'=>3), array('value'=>4, 'title'=>'four'));
    $s = array_sum(array_map("extract_value", $d));

Cracks come forward and shorten it please (in any language!).

Comments (28)

Mayflower Barcamp - awesome!

Mayflower had invited me to join their Barcamp last weekend - and it was awesome. Thank you a lot!!!
We had been a crowd of about 40 people all hacking all day long until deep at night, it was a great atmosphere and some very interesting projects had been made. I am sure some things will come up on the Mayflower blog soon, just keep watching!
I was mainly working on integrating the dojo.grid into the next version of Phprojekt and doing some ground work for a very flexible structure. And I have learned a lot more about dojo again. It’s just great!
Besides that I was advocating a lot for Python and Django especially :-), I just can’t hold back. But it’s hard to convert anyone there, since Mayflower is the biggest and best PHP service provider in Germany and the people there are really good in what they are doing! Though one came up to me and said “thank you for putting the Python book on the table” (which I did a while ago in the Mayflower office, just for fun).
Thanks again and hopefully see you soon again.

Comments

Google Test Automation Conference 2007

The titles of the videos look very much like “must watch”. Found via ThinkPHP, thanks.

Comments (2)

Bug or feature? - Beature

>> $data = ‘12345′
>> isset($data['foo']) ? ‘beature’ : ‘not set’
beature

I am just hacking away and just shrug. My AJAX request returns the following POST data data=[Object object]. Well, dojo obviously doesn’t resolve nested objects, so I get the ugly object string there. Ok, no problem.

But the interesting part here is that my PHP code behind expects an array and since I hadn’t implemented a type check the isset($data['foo']) returns true. What PHP does here (thanks to Alex Haslberger for the help figuring it out) is, it converts ‘foo’ into a 0 and uses the string $data to check if it has a character set at position 0. Which is true, of course.

I understand (don’t agree) that in PHP 1+’[’ returns 1, but the case above reveals that it might not be a good idea. Currently the type check has to be done by hand, which would be is_array() in my case, but is that really the right way?

I don’t feel like stressing my brain much more with it now, I am just too curious about our (Germany) quarter final game against Argentina … “don’t cry for me Argentina” :-)

Comments (3)

PHP on Rails *yawn*

I have no experience with Ruby on Rails I just know the screencast and am reading about all the hype. But I think I know PHP quite well, so I wanted to know how much people had learned from RoR and how it has effected the PHP community, especially concerning frameworks and stuff to make your life easier. Here is an article Rails-inspired PHP frameworks from H3rald, which is not going very much into depth. But from what I read symfony seems very promising, especially because it has I18N support integrated and extensive docs, which I think are musts nowadays. I haven’t worked with neither one of them, but I probably will.

Let me just state that I think the integration of AJAX is pretty neat and comfortable, but when it comes to really dedicated JavaScript stuff I would probably not use it. And the Web2.0 stuff nowadays does really dedicated JavaScript. But we will see how this is evolving …

Comments (7)

Finally a real PHP Shell

After working with Python for a while and enjoying the pleasure of having a shell where you can test your code before you actually programm it I came back to PHP and missed the shell big time. Especially when you don’t exactly know how to use special objects or functions. Now the pain of not having such a shell is over, Jan wrote the real shell for PHP. Thanks a lot. This will make testing and just playing with PHP so much easier. It provides of course auto loading of classes.

Install
Download the actual PHP_Shell class here, and rename the file to “.php”. Download the php-shell script, that you want to start later, from the command line here, rename it to “*.php” too.
To make it callable from the command line using “php-shell” you might want remove the “.php” from the later file too and put either both in one directory that is globally reachable (that is in your PATH). The other opportunity, when you don’t want the PHP_Shell file in you bin-directory, would be to put the PHP_Shell class in the include_path, but then you have to adjust the php-shell script to not include the PHP_Shell from “./PHP_Shell”, but as “PHP_Shell”.

Have fun …

Comments (7)

Foreign key constraints, DB for real

Now that I am a happy user of PHP5 and MySQL5 and using that for writing a new application, which fortunately involves using the newest technologies, I am finally able to solve one of the biggest issues I always had had with DB-driven applications: foreign key contraints.

Constraints and transactions
I am using InnoDB (I know those contraints had been possible before MySQL5) for that and the first time I am also using the foreign key constraints InnoDB provides. And it does make me happier :-). I don’t have to take care of updating and deleting all the referenced table rows myself, the DB’s storage engine does that for me, as I always had wanted it.

I had started out using MyISAM tables and triggers, but when I realized that I am programming the application using transactions I had to switch to InnoDB for it to have any effect at all. Transactions solve the next problem I always had, uncompleted or failed database modifications.
I upgraded my mind too and was able to drop the triggers, doh. Oh man, that was a long process, even though all this knowledge was available already in some corner of my mind.

Watch out
But I actually wanted to write down the one thing that I had been looking for for a while:
Create foreign keys only on columns with the exact same type!
Of course. Yes, of course. Makes sense, but I just wanted to have a go and try the foreign key constraint and didn’t watch out for the types, then I got the error:

ERROR 1005: Can’t create table (errno: 150)

And the manual just told me the standard things, but not this!

Won’t work
CREATE TABLE chapter (
chapter_id int(10) NOT NULL auto_increment,
title varchar(20) NOT NULL,
PRIMARY KEY (chapter_id)
) ENGINE=InnoDB;

CREATE TABLE subchapter (
subchapter_id int(11) unsigned NOT NULL auto_increment,
chapter_id int(11) unsigned NOT NULL,
title varchar(20) NOT NULL,
PRIMARY KEY (subchapter_id),
KEY chapter_id (chapter_id),
FOREIGN KEY (chapter_id) REFERENCES chapter(chapter_id)
ON UPDATE CASCADE ON DELETE CASCADE
) ENGINE=InnoDB;

The two columns chapter_id are of a different type, int(10) and int(11), and one is signed the other unsigned! Only if you get both types exactly right the creation of the foreign key constraint will be successful! Otherwise you get the meaningless error message mentioned above, which does not really help.

Will work
CREATE TABLE chapter (
chapter_id int(11) unsigned NOT NULL auto_increment,
title varchar(20) NOT NULL,
PRIMARY KEY (chapter_id)
) ENGINE=InnoDB;

CREATE TABLE subchapter (
subchapter_id int(11) unsigned NOT NULL auto_increment,
chapter_id int(11) unsigned NOT NULL,
title varchar(20) NOT NULL,
PRIMARY KEY (subchapter_id),
KEY chapter_id (chapter_id),
FOREIGN KEY (chapter_id) REFERENCES chapter(chapter_id)
ON UPDATE CASCADE ON DELETE CASCADE
) ENGINE=InnoDB;

Let’s see what’s coming after InnoDB …

Comments (10)

PDO newbie experience - unbuffered query

My PHP5 and PDO (PHP Data Objects) experience is very young (to be exact: one day), but I have already learned an important lesson, which is rather a mysql lesson, than PDO, I guess.

PDO default is unbuffered query
I had the simple code:

$dbh = new PDO(’mysql:host=localhost;dbname=test’, ‘root’, ”);
$dbh->prepare(’SELECT * FROM test WHERE test_id=?’);
$dbh->execute(array(1));
$dbh->fetchColumn(0);
$dbh->prepare(’SELECT * FROM test1 WHERE test1_id=?’);
$dbh->execute(array(2));

It always gave me a “Call to a member function execute() on a non-object” in the line of the last execute(). I was really speechless. I even tried to create a new PDO object every time, that seg-faulted on me. It wasn’t the right thing to do anyway, so that was ok.
With Johann’s help we found out that the unbuffered query is the problem. I didn’t retreive the complete result set (I only do a fetchColumn()), so there is still an open result set on the server. And a new execute() is awry. Calling a fetchAll() after the fetchColumn() helps, but is not what you want to do. The solution is to use buffered queries, create the new PDO object with the attribute PDO::MYSQL_ATTR_USE_BUFFERED_QUERY set to true, like so:

$dbh = new PDO(’mysql:host=localhost;dbname=test’, ‘root’, ”
,array(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true));

Ilia already mentioned this problem last year. Anyway it still seems to be a point that needs to be stated clearer in the docs. I am happy I learned something. That’s not bad for one day PHP5 and PDO.

Why not Python?
If you followed this blog and are wondering how come that I am doing PHP again, well it is the simplest to get running. I would love to do it in Python, but getting set and started simply takes much more time, and I just want to get a prototype out the door. I am also much more familiar using PHP and my latest experience with the EXIF stuff for Python doesn’t make me very optimistic, that Python is easy enough to use for all the web tasks I expect to do.
I am sure that if I did about a month of this stuff in Python I will have understood it all too, but I don’t have this time now, unfortunately. But at least I have the plan to redo it all in Python (btw. I have many plans).

Comments (3)

PEAR Tree package

Quite a while ago I had written a package for the PHP Extension and Application repository (PEAR) that tried to handle trees. It had started out as a simple package, which was handling trees by a “brain dead” method, but later I had added Nested Sets and other more clever ways. It is now already quite a while ago that I had given up maintenance but I am still getting requests about the package, not very often, but from time to time it happens.
I will list some links that hopefully help out.

A PEAR::Tree Tutorial by Demian Turner, a very good starting point!
The official PEAR online docs, if you don’t like looking into the source try this.
An article for the PHP Magazin where I described how to use Tree (german).

Btw. the os.visionp.de web page, that had some more extensive documentation on it had been taken offline.

Comments

TestOOB - Finally learning again

I finally found some challenge again. I am learning again, I am reading source code that really is nicely written and well structured. I have the feeling that got somehow lost in my PHP days. The TestOOB source makes use of various design patterns, where it makes sense and is thread-safe. Somehow it seems that the language Python attracts the people that really understand those concepts and the level of programming is much higher than in most PHP projects. That is a challenge and it will take me a while to make it up to understand it all and to feel comfortable at this level, I am very excited about the upcoming time. That is the salt in the soup of a programmers life. Yeah!
Read the rest of this entry »

Comments (2)

phpSqliteAdmin Installation

I wanted a simple web based “download and run”-SQLite browser. So my choice was of course a PHP tool, first thing to look for is something like phpMyAdmin just for SQLite.

There are two of them, with the same name “phpSQLiteAdmin”:

  1. One by Yves Glodt
  2. Another one by Richard Heyes

and none of them works out of the box! So here is what I did to get number 2 (phpSQLiteAdmin by Richard Heyes) running.
Read the rest of this entry »

Comments

Install PHP+MySQL vs. Compiling it

I used to like to compile PHP myself, that just felt geeky. It made me feel special, just as if I was almost a real geek, nerd or whatever. I liked to torture myself and install other packages and dependencies before. But only the right version please! I liked to find out that the order of the –with config-switches made a difference. I liked to watch the configure process running for quite a while to finally see that another error occured again! I liked to watch the make and see it fail with some missing dependency or some library it could not link because the exported symbols didn’t match.

NO, I didn’t!

It was always an aweful waste of time. But somehow it made me understand better, what happens underneath. And sometimes it also made you look into the source code, which definitely was not bad. But at the current level of specialization that people have, it might need to be avoidable.

What am I saying here? I needed to have PHP and MySQL running on my Mac - quickly. The Apache fortunately is already running by default (just switch it on in the System Preferences/Sharing). So I started to compile PHP, which was taking too long in my eyes. After two or three errors because of missing deps I knew that was going to take longer. Back to the web and search for a .dmg! But a certain version of PHP, as the customer requires it! That was really easy. Thanks to Marc Liyanage you can find a lot of different binary versions of PHP at entropy.ch. And installing MySQL is not a problem either. There are enough different binary versions of MySQL. Now I only had to modify the /etc/httpd.conf and/or /private/etc/httpd/users/<username>.conf and set the proper DocumentRoot and Options I needed and I was done. Cool! That’s what I call usability, very nice.

Less pain - more spare time :-)

Comments (1)