Posts Tagged ‘PHP’
The webJestic Engine Project
I’ve already gotten a head-start on a PHP application engine. I’ve created a Google Code project for it and initialized the SVN trunk with a check-in. As it is right now, it’s a basic Zend Framework shell with an inherited Smarty object to manage templates. There isn’t much to it at the moment, but the template engine is doing it’s thing.
The project will of course be following the phpDocumentor comment and code standards, and taking advantage of the // TODO: commenting practices used in PHP for Eclipse.
I still have a pretty tight schedule, but I’ve already begun planning out content and development.
Delphi for PHP (my verdict)
After having used Delphi for PHP to build an application framework, I managed to figure a lot of things out. I had to dig into the VCL and make some changes, search through tons of useless online documentation, and build and rebuild to finally get something I felt was fluid and sensible.
I’ve been a Delphi application developer since version 1, and I’ve grown with Delphi and it’s IDE and development style over the years. I’ve created dozens of custom components, taken advantage of it’s undocumented objects, and became involved with the Open Tools API.
I believe Delphi can be used to write some extremely poor applications, and I know it can be used to create some very slick applications as well. It’s all in the architecture and the developer who writes the code. Events can be elegant or nasty, depending on the experience the developer has with the IDE.
I tried to follow good practices in the Delphi for PHP environment. I’m not a fan of data-aware development in either Delphi environment, but I played with the technology in Delphi for PHP. I followed the rules, studied the code, and created some applications that took advantage of the templates, libraries, and it’s AJAX architecture.
After some very simple and mildly complex applications, written the way I believe Delphi for PHP was intended to be used, I gave up on it. Ignoring the weight of the VCL and just trying to make a decent application with an open mind (and some high hopes), I just couldn’t keep my code simple and elegant. I also couldn’t consistently produce XHTML/CSS code that remained W3C compliant or validated.
The future of Delphi for PHP is always in question when you are determining the direction of an application. Will it be supported in 5 years? Will they improve it? Can it even be improved? Will the VCL stand the test of time? Will there be a pool of developers to draw from when it comes time to hire an employee?
I just cannot believe it has a bright future as a commercial development environment, especially when there is an entire force of PHP developers openly improving upon Eclipse for PHP. With that said, I could in no way recommend a client begin new development with this product. In my opinion, they would eventually be stuck with a heavy weight application that can’t meet W3C standards, has outdated and neglected libraries, and frowned upon my any respectable PHP developer.
This is where I stand with Delphi for PHP and will no longer be creating articles or videos in the Delphi for PHP IDE.
I will however, be contributing content to PHP application development using Zend Servers and Eclipse for PHP, as well as some of the Zend Framework.
Working with MySQL Auto Incrementing Keys
If you’ve been working with Firebird, Oracle, or any number of other databases, the first thing you’ll want to understand is how to work with MySQL auto_increment keys. Anytime you work with keys that are auto incremented by the database engine, you will need a way to retrieve the key values for your insert statements. Relational database are built on joins and understanding how to assign your foreign keys is essential.
Using MySQL to manage your foreign key inserts you can use the LAST_INSERT_ID() function. This allows you to directly insert the value for your foreign keys without having to execute a query or some other mechanism. The LAST_INSERT_ID() MySQL function returns the value of the PRIMARY KEY previously inserted.
This works perfectly for simple designs where only a single foreign key exists and you want to link to the master table.
Example: Tables used
-
CREATE TABLE web_template (
-
id bigint(20) NOT NULL AUTO_INCREMENT,
-
template_name varchar(30) NOT NULL,
-
template_location varchar(100) NOT NULL,
-
-
UNIQUE KEY template_name (template_name),
-
PRIMARY KEY (id)
-
) TYPE=InnoDB DEFAULT CHARSET=UTF8 AUTO_INCREMENT=1000;
-
-
-
CREATE TABLE web_config (
-
id bigint(20) NOT NULL AUTO_INCREMENT,
-
config_template_id bigint(20) NOT NULL,
-
-
PRIMARY KEY (id),
-
FOREIGN KEY (config_template_id) REFERENCES web_template(id) ON DELETE CASCADE
-
) TYPE=InnoDB DEFAULT CHARSET=UTF8 AUTO_INCREMENT=1000;
Example: Insert statements
-
INSERT INTO web_template (template_name, template_location) VALUES (‘Default Template’, ‘/template/Default/’);
-
-
INSERT INTO web_config (config_template_id) VALUES (LAST_INSERT_ID());
In PHP we have the mysql_insert_id() function, which allows us to retrieve the last key inserted. This function works pretty good, but it must be executed before you commit your transaction, otherwise you might get unexpected results. Additionally, it’s ideal to execute the statement directly after you submit your insert statement.
Using this function gives us more flexibility in key management in our applications, especially when working with tables that have multiple foreign keys.
Example: PHP statements
-
<?php
-
mysql_query("insert into web_template (template_name, template_location) values (‘Default Template’, ‘/template/Default/’");
-
?>
Note: In a “data aware controls” environment, it’s not always easy to manage your auto incrementing keys (a lot of this is due to design, not just environment). In most cases where I have the decision making power I try to avoid data aware control development (especially on the web, now that Delphi for PHP is available). Read only grids are an exception, but most of the time you can design your applications to avoid “live data aware” entry/edit forms. It may seem like more work, but I believe in the end it’s cleaner and easier to debug.

