Delphi for PHP Update 1 Hits the streets

OK folks, the long awaited update has been released from beta testing.

You can get it yourself right here: http://dn.codegear.com/article/36406

There are some good fixes in this.  The big one for most folks will be the input filter fix.  For many the UTF-8 cleanup will be a god send.  Deployment tweaks are included too.

In fact here’s the complete list:

  • Fix to the IDE to ensure correct storage of UTF-8 strings in the .xml.php
  • Fix to VCL for PHP to parse .xml.php in UTF-8 mode
  • Save Project As… fixed (QC 43580)
  • Updated sourcecode documentation for the VCL
  • Fixed problem with PHP 5.2.1. The Input Filter extension is out of beta and function for filter data was changed to a new name, so Input object now takes that into account (QC 43607)
  • Fixed problem with vcl-bin folder. The alias is set to be a root alias, making it easier to configure on deployment
  • Added global var to specify if properties are html_decoded when read from the .xml.php
  • Corrected support phone list .txt file

Enjoy!

How to have a central VCL for PHP location for all your websites

I have a number of sites that on which I want to use the VCL for PHP library components with Delphi for PHP creations.  I don’t want to waste uneeded space for a bazillion copies of the VCL.  As far as that goes, I don’t want to have to sit through the deployment wizard every time either.

You could edit PHP.ini and add the location to your include path, but the VCL for PHP is MORE than just a textual code libary.  It includes image files as well, for things like the dropdown arrow in the combo boxes.

 So what’s a person to do?  Well, it’s simple.  Create some symbolic links!

Just put the VCL in your root directory or at least one that can be accessed with a common path from the your website directories.  I use the root since I can use ~ to get at it easily on Linux.  It could just as easily be /usr/local/lib/vcl or d:\VCL.  Then in your directories you just put two symbolic links, one named vcl and the other named vcl-bin. Both pointing to the vcl directory you made.

Here’s the step by step for *nix systems:

  1. Upload the whole VCL folder to the root web directory
  2. Telnet/ssh into the account
  3. Change to the directory for your website
  4. Run these two commands
    1. ln ~/vcl
    2. ln ~/vcl vcl-bin
  5. Repeat steps 3 and 4 for all of your sites.
  6. When you deploy, just grab the files in your project directory and upload them.  No worrying about the VCL any more.  You should be able to make a batch file that does that step!

That’s it (oh and just in case your font makes “ln” hard to readand that is a lower case “LN” as in link.)

 On Windows, you should be able to do the same thing.  If you have Vista you have native support for symbolic links.  And in XP, you can use NTFS links.  But I’ll leave it up to you to look up those technologies.  With that sort of thing, if you aren’t able to find and digest how to do it, you’re probably better off just using the deploy tool.

 Hope this helps someone!  It’s made my life a little easier.

Windows Implementation

Kevin Berry came up with this windows implementation:

For my Windows 2000 webserver, which I have total acces to, below is how I followed Brian Layman’s advice to made this work.

1. Downloaded linkmagic.exe from
http://users.pandora.be/jbranders/linkmagic.exe

2. Ran linkmagic.exe (setup program) on my webserver.

3. Launched Junction Link Magic program.

4. Created empty “vcl” folder in my clock project folder in my webserver root (c:\web\htdocs\clock\vcl) and selected this vcl folder as my junction folder.

5. Selected my true vcl folder loaded with vcl files as my destination folder (c:\web\vcl)

6. Clicked “create” button

Now my D4PHP clock sample program runs just fine in c:\web\htdocs\clock with only one main vcl installation on my webserver.

I suppose I could use the Junction Link Magic program to create new vcl junction folders in other vcl project subfolders on my webserver, but I discovered that once the first vcl junction folder is created, I can create more of these just by copying an existing vcl junction folder into a new project folder and choosing cancel when the file overwrite prompt appears. If I delete a vcl junction point folder, the real folder and its files don’t get deleted.

I for one don’t want different versions of my vcl all over my webserver in different folders (assuming I’ll have lots of web projects someday). For me it’s just simplest knowing the latest and greatest vcl library is always in one spot on my web server.

I don’t know if one could duplicate the directory structure of a windows hosted web from a remote server on one’s own computer to create the junction folder and then ftp that junction folder out to the remote server and preserve the redirection. If so, that would be great.

For my webserver, this is pretty nifty, Thanks again to Brian for the workaround until Codegear/Qadram figure out what I hope to be a better vcl deployment method.

Alternative Solution

David Plock also suggested another methot that uses a VCL-BIN alias. Jose Leon Serna provided the final fix to get this working. Kevin has done a great job of writing up these steps as well:

Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all

3. In my php.ini file I added the following so that php will know in which folder to find the vcl folder.

include_path = “.;c:\web”

If I had dropped my vcl folder into my root directory on my webserver, the entry would have been:

include_path = “.;c:\web\htdocs”

4. Jose added the final piece to make this work. In my vcl.inc.php file I modified a line so that the alias name gets passed properly to my webserver. The line that mentions vcl-bin needs a forward slash in front of vcl-bin so the final line appears like this:

if (!array_key_exists(‘FOR_PREVIEW’,$_SERVER)) $http_path=’/vcl-bin’;

5. Make sure all configuration file changes above are saved and then restart the webserver.

Now you can drop D4PHP projects in any subfolders or even subfolders of subfolders of your root directory on your webserver and they work.

The nice thing about this solution in addition to it being a single vcl deployment is that it seems to me any web hoster can implement it once for
the entire web server and any subscribers can simply ftp D4PHP web files to their own folders on the server and they’ll work.

Thanks Brian, David, and Jose for two ways to make a single vcl deployment work!!!

If you want to see this solution in action, you can visit these links (on my slow webserver) for as long as my internet service provider leaves my ip address alone. The vcl folder is outside the web root and only clock.php, clock.xml.php, and background.gif are in each of these folders.

http://24.2.90.16/clock.php
http://24.2.90.16/clock/clock.php
http://24.2.90.16/clock/clock/clock.php
http://24.2.90.16/clock/clock/clock/clock.php

There you are. Two different methods proven successful in the field! Enjoy!

Wahoo! I did it! The last part of a WP-DB.PHP for Interbase/Firebird

I knew 9 years of IB/FB experience would come in handy.

wp-db is the mini database abstraction layer for WordPress. It allows you to run WordPress on various database. Right now MySQL is pretty much it, but some folks have been doing a PostgreSQL version as well. 

Well, I wanted it to connect to an Interbase db for the .TEXT blog conversion I’ve been doing.  I’m not going to run WordPress off of Interbase yet, but it simplified the import for me to use WP-DB for my database import connection.

It’s interesting to note that I’ve come to the point where the other editors that I’ve been using for PHP code just don’t feel right anymore. Delphi for PHP just feels better now for editing.  I wasn’t doing any visual designing in it, but it was still a nice quick editor with the additional help of hints and parameters.  Maybe if I had Zend, I would stick with that for non visual stuff, if I were used to it, I don’t know.  I don’t have it.  I tried it once and found it too bulky for my needs.  D4PHP with all of the design boxes closed, still feels light and has a quick open time.

Anyway, most of the conversion was pretty easy. I just had to substitute ibase_ php calls for mysql_ calls.  I had to add a little cleanup for handling of empty strings and quotes and some reserved IB words like type, role, password, and etc.  But the really problem was that WordPress relies heavily on the InsertID feature that many databases have.  It returns the last value of the autoinc field in the table referenced by the last insert command.  IB/FB has no equivelent.  PHP documentation did not indicate any solution was provided. And all of the database abstration layers out there don’t support it either.

So, I’ve done a work around.  It is possibly not 100% accurate for all databases configurations out there, but it should work for WordPress and .TEXT. 

See, the trick was to find the primary key for the table you are working on.  So, first  I had to find what table I was working.  I had the SQL INSERT statement, so all I needed to do was find the table name after the words “INSERT INTO “.  Fine.  There are a bunch of ways to do that.

Next, armed with the table name, I had to find the primary key.  How do I do that with just the commands available to PHP?  That was the tricky part. 

Luckily, IB/FB is a relational database.  That in short means the tables are all stored in bits and pieces throughout the database table and then linked back together according to the structure information stored in “hidden” tables.

The long and short of it is that this statement will give you what is needed:

[SQL]
select RDB$RELATION_CONSTRAINTS.RDB$RELATION_NAME, RDB$INDEX_SEGMENTS.RDB$FIELD_NAME, RDB$INDEX_SEGMENTS.RDB$FIELD_POSITION
from RDB$RELATION_CONSTRAINTS, RDB$INDEX_SEGMENTS
where
RDB$RELATION_CONSTRAINTS.RDB$CONSTRAINT_TYPE = ‘PRIMARY KEY’ and
RDB$INDEX_SEGMENTS.RDB$INDEX_NAME=RDB$RELATION_CONSTRAINTS.RDB$INDEX_NAME
order by RDB$RELATION_CONSTRAINTS.RDB$RELATION_NAME, RDB$INDEX_SEGMENTS.RDB$FIELD_POSITION

[/SQL]

In WordPress and .TEXT every AutoInc field I looked at was the first field in the table.  So, now armed with the table name, and autoinc field, it is a simple query to get the highest value, which should be the most recent insert unless there’s been some kind of corruption.

So that’s just a select Max(fieldname) from tablename statment and I return the value I’ve found in field one  (handling an empty result set of course). 

 Hey – It’s not pretty, but it should work 100% of the time for my uses.  If it does, I’ll submit it to ADOdb and see what they think.  Since ADOdb is a core part of the Delphi for PHP project, I might get my little bit of code included!  Actually, I hope to contribute to the VCL for PHP long before then.

 OK, everyone’s eyes have glazed over but it’s still pretty cool honest!

Some basic PHP calls for use in Delphi for PHP or pure PHP

I was doing some coding today and couldn’t find some routines I’ve used often in the past.  Since I had to search for them, obeying my rule, they get posted here.  Maybe they can be of use to others.  These are examples I’ve written and once I’ve collected and customized.  I’ve not put comments in most of these routines, sorry.

(THIS IS A LIVING POST AND WILL CHANGE PERIODICALY AS I DIG UP OTHER COMMON ROUTINES)

Clean an array of all vulnerabilities:

[php]

function strip_and_slash_deep($value) {
return is_array($value) ?
array_map(‘strip_and_slash_deep’, $value) :
strip_tags($value);
addslashes($value);
}

[/php]

Use:

[php]

$protected_post_vars = array();

$protected_post_vars = strip_and_slash_deep($_POST);

[/php]

My print_r replacement to print an array in full depth:

[php]

function print_array($array)  {
if (is_array($array))
{
reset($array);
while (list($key, $val) = each($array))
{
if (is_array($val))
{
while (list($akey,$aval) = each($val))
{
$array[$key][$akey] = strip_tags($aval);
echo “Array: “.$key . “=” . htmlspecialchars($array[$key][$akey]).”<br/>”;
}
}
else
{
$array[$key] = strip_tags($val);
echo “Val: ” .$key . “=” . htmlspecialchars($array[$key]).”<br/>”;
}
}
}
else print($array);
}
[/php]

Basic structure for using PHP to connect to an interbase or firebird database:

[php]

function ib_execsql ($sql) {
$aresult = array();
$fulldbpath = “localhost:d:\blah.gdb”;
$username = “sysdba”;
$password = “masterkey”;
$ib = ibase_connect ($fulldbpath, $username, $password,’NONE’, ‘100’, ‘1’);
if ($ib===false) echo “No Connection”;
$result = @ibase_query ($ib, $sql);
if ($result===false) echo “<hr/>Error ‘”.ibase_errmsg().”‘ while executing ‘”. $sql.”‘<hr/>”;
while ($row = ibase_fetch_row ($result)) $aresult[] = $row;
ibase_close ($ib);
return $aresult;
}

[/php]

use:

[php]

$array = ib_execsql(“select * from whatever”);
print_array($array);

[/php]

Run a single query across many databases on the same MySQL server:

[PHP]

function execdbsql ($databasename) {
$link = mysql_connect(‘SERVERNAME’, “USER”, “PASS”);
if (!$link) {
die(‘Could not connect: ‘ . mysql_error());
}

mysql_select_db ( $databasename );

$result = mysql_query(‘SELECT desiredfield FROM tablename where field=”keyvalue”‘);

if (!$result) {
return;  // Don’t error out just skip this database.
}

echo mysql_result($result, 0).”<br/>”;

mysql_close($link);
}

echo “Values:<br/>”;

execdbsql (‘firstdb’);

execdbsql (‘seconddb’);

execdbsql (‘thirddb’);

[/PHP]

Is Delphi for PHP better than Delphi 1.0?

Eric Wilms of WilmSoft.com left a comment on an ealier post.  My reply was way to long for a comment, so I’ve turned it into a post.  Then I can get other people’s feedback.  I’ve found people rarely ever read the comments here since most of my posts show in full on the front page…

Let’s catch you up on the story so far…

Eric wrote:

I’ve got the first release of Delphi 4 PHP… I have to say I’m VERY disapointed… I’m a Delphi code since Delphi 1 and PHP programer since 1998 and the thought of a Delphi for PHP was a dream come true. However, I can’t not get it to run any “app” on my Hosted server. The code runs fine on my local machine but, that’s not where my web sites are hosted. I HAD to upgrade to PHP 5.X.X.X in order to even get anywhere on a simple Hello World. I have no issue with that execpt it’s not really mentioned anywhere in the specs… Also, I was completely dumbfounded to find that there was NO FTP built in to Delphi 4 PHP… Come on guyes! You have to “delploy” you project (which puts all the files you’ll need together in one spot then open up your favorite FTP program and copy them to where you want it…. So, that means a simple change is not a click of a button away to update… you have to click deploy and about four “next” buttons to have it “deploy” THEN open your FTP and copy the files to the server…. That is a Joke.

Just calling it Delphi and hoping it will change the way things are done (Like Delphi ONE did) will not change the way things are done. I’m back to hand coding in my Favorite PHP editor. At least when I hit save, it saves it via FTP back to the server it came from….

I wish I could get my money back… :(

To which I said: 

Well, I do understand where you are coming from.

But I can’t say that either of those two things were not issues for me. I usually use PHP 4, but php 5 was always there for me to enable with a simple .htaccess change. Your past that anyway.

As for the FTP setup, I agree that would be nice too, but I don’t need it either as I use the old Novell add on util NetDrive ( abandonware publicly distributed for free to students) to make my debian webserver’s root drive X: on all of my machines, even my laptop. There are a bazillion instruction pages at colleges and elsewhere explaining how to use it, but I really don’t think you need it. Here’s one set http://www.loyola.edu/5555/netdrive/installingnetdrive/

I know lots of people use similar solutions so that their FTP account is just a drive letter on their windows sever.   Maybe it will help the transition for you… The public goal for Delphi for PHP v1.0 was always a Delphi 1 level of ability. It’s surpassed Delphi 1 in MANY, MANY ways, but I can’t deny there are some rough spots that require attention.

And Eric wrote back (OK this is the last quote):

I’m curious (and a die hard Borland….er ahem… Code Gear fan) what do you see as: “It’s surpassed Delphi 1 in MANY, MANY ways, ”

Because for me and Delphi one (coming from VB) was I Dropped down a button, a label and pressed F9. Bam! done… And every thing from “hello world” to middle-ware client server app doing OLE (or what ever) was just as hard (or simple).

I Dropped down a Calendar in D4PHP, do the deploy, copy the files to my server and I get: “Warning: require_once(vcl/jscalendar/calendar.php) [function.require-once]: failed to open stream: No such file or directory in /home/wilmsoft/public_html/delphi/vcl/vcl.inc.php on line 127″

Is that a rough spot? Do I really have to dig in to the source code to figure out what’s missing the vcl.inc.php file?

I hear what your saying about the FTP and figured that would be the general response. But, I’m a contract programmer. I never am “on the server”. I almost always am on someones remote server where I don’t have access to a simple .ini file. I can’t use this tool and make money as it is today. I made money DAY ONE with Delphi One. No telling the customer oh, I’m glad you hired me to fix such and such but, I need you to now use change your infrastructure so my tools work.

I thought (or hoped) that the code gear spin off would start to focus (again) on the little guy writing code not the corporations… and I do see that trend and felt like I need to preorder D4PHP. But, Code Gear bought Delphi 4 php and I think it’s going to take a few releases to get it where they want it. Version one is not there yet. I wish I would have waited for the demo before I put down my money….

And this may not be the place for this conversation but, I couldn’t find any place on Code Gear’s site to vent. I am interested in other peoples view on this potentially awesome product.

So there we are.  This is my reply… 

Well, first off, “How does Delphi for PHP surpass the Delphi 1.0 feature set?”  I’m not going to be able to give you a exhaustive list in without giving it more serious thought, but I can rattle off a quick ten ways Delphi for PHP is improved over Delphi 1.0:

  1. Code completion springs instantly to mind.  Delphi for PHP’s use of code completion is hindered compared to current Delphi versions because PHP is not a strongly typed language.  But, there was nothing to compare to it in Delphi 1 AFAIR.
  2. Datamodules are another addition.  They were introduced in d3, I believe, and take the clutter off of your design forms and allow you to share the database structure across various forms.
  3. If you deployed BDE apps in D1, you should remember that the end user had , until the setup programs caught up. That’s handled for you, though here too there are technical difficulties on the D4PHP side.  So perhaps this one is  a wash…
  4. The Code explorer didn’t exist in Delphi 1.  You couldn’t easily go between unit and unit.  As far as that goes I don’t think Ctrl-Enter worked to open the unit from the uses list either.
  5. Project Groups have been added allowing you to have several projects on a single website.
  6. There are numerous more advanced controls in the tool pallette AND a way for the community to have input and an affect on the behavior of these controls.
  7. The applications you produce are themed, that certainly wasn’t the case in Delphi 1.  Delphi 1 apps didn’t even minimize in quite the same fashion as other Windows Apps.  Because of TApplication IIRC, your main form wasn’t REALLY your main form and you had this double minimize thing going on.
  8. The Data Explorer and all of its numerous features certainly didn’t exist.
  9. Internationalization (I18N) was in its infancy in Delphi 1 days.
  10. Pinning, expansion and restoring of the debug & development “windows” in the IDE allow you to have a much more dynamic IDE than was ever possible in D1.

I’m sure there are plenty of other things to add and the list can be debated, but if you install Delphi 1 again, you might be surprised at the feel of it compared to what we have in today’s delphi.  I was when I did just that last year.

Now I do agree that saying that Delphi for PHP had “Rough Spots” might be a bit rosey.  I also agree that Delphi for PHP could have baked for another month in the oven.  If it would leave a better taste in everyone’s mouth after the first bite.  But if you have more than a day to look at this stuff, you find that there really is some worth here, but it is a paradigm shift that takes some getting used to.   Somethings work really well and somethings… not so much.  D1 was not much different if you got in early enough.  The whole concept of design time libaries and run time libraries and deploying artificially thin EXEs had everyone pulling their hair out for a while. 

With Delphi for PHP, there’s another hurtle to over come.  You are switching from a Native API design environment, into a designer that IS a webrowser and javascript interpreter.  In order to have live components, the designer now has to execute all of that web code.  So there is a significant speed cost to that.  The equivelent would be writing a Delphi app that would use a TWebBrowser component to load rich web pages again and again and again. 

I’m not sure I understand the logic of the one day trial idea in this sitation.  Nothing makes people crankier than a ticking clock, working with something never seen before, things not working right, and a significant money decision on the line.  I’m not sure combining all of those issues into one program was the key to success when taking API developers and putting them in a web environment for the first time.  But…that’s the situation.

There are definately things that you can do to make your situation better.  First, I totally agree with you about the calendar thing. I logged an issue for it here:
Report No: 43501            Status: Reported
js Calendar does not deploy with the deployment wizard
<a href=”http://qc.codegear.com/wc/qcmain.aspx?d=43501″>http://qc.codegear.com/wc/qcmain.aspx?d=43501</a>
ALL of the javascripts should deploy with the rest of the application.

Now that said, there is no reason that you can’t have the full VCL directory already deployed on your site and in that directory. 

I’ve actually taken that one step further.  I have ONE copy of the VCL for PHP for all of my websites.  I hung it off of my web root.  I allow my Delphi for PHP apps to access it by creating symbolic links in the directory containing the Delphi for PHP files.  Just put the VCL up there in your root (or wherever) and then telnet/ssh into your account, change to a different directory and then run these two lines:

ln -s ~/vcl
ln -s ~/vcl vcl-bin

The vcl-bin path is required for images used in the components.  There are other ways you could do this too.  You could just link the vcl-bin for example and then have a custom PHP.INI file in your directory that adds the vcl to your include path.  This solution, though, I think is the most generic.

When you have this done, you should never need to deploy your app again, and can just create a batch file that multi sends only your stuff to the website.  I’ve not experimented much with this solution, but it seems to work fine with all I’ve done with it so far!

Well that did not take long: Delphi for PHP Warez and torrent files

That didn’t take long at all!

Look at this… A simple Google search and there there are all these copies available to download at one site…

The AMAZING thing is that some of these were well within the beta period before the final product was a available. And the size of them? Greater than a single CD? If you download and install this stuff what the heck will you be putting onto your system??? If this doesn’t scare you away from random warez sites, I don’t know what will. So many of them exist SOLEY for the spreading of worms and the like. Well, of course your favorite site for downloading illegal software is an exception. They’re totally honest – as are those people hosting the torrent seeds. You could trust them with anything!

delphi for php *DEVIANCE*

360kb/s  

158.42 MB  

2007-03-27

delphi for php [FULL-CD]

242kb/s  

4209 MB  

2007-03-27

delphi for php WinXP

122kb/s  

3738 MB  

2007-03-27

delphi for php *PAL*

359kb/s  

227.10 MB  

2007-03-27

delphi for php *PAL*

288kb/s  

958.03 MB  

2007-03-24

delphi for php WinXP

374kb/s  

101.46 MB  

2007-03-24

delphi for php (06-07)

99kb/s  

57.02 MB  

2007-03-23

delphi for php *PAL*

53kb/s  

264.41 MB  

2007-03-21

delphi for php [FULL-CD]

156kb/s  

264.41 MB  

2007-03-21

delphi for php ISO

159kb/s  

89.91 MB  

2007-03-21

delphi for php Latest version

209kb/s  

68.96 MB  

2007-03-21

delphi for php [KEYGEN]

110kb/s  

637.89 MB  

2007-03-19

delphi for php *PROPER*

75kb/s  

259.27 MB  

2007-03-19

delphi for php *DEVIANCE*

243kb/s  

700.01 MB  

2007-03-17

delphi for php [KEYGEN]

306kb/s  

75.02 MB  

2007-03-12

delphi for php WinXP

14kb/s  

75.02 MB  

2007-03-12

delphi for php CRACK

108kb/s  

44.40 MB  

2007-03-04