Author Topic: PHP Script Development  (Read 15752 times)

0 Members and 1 Guest are viewing this topic.

mgpw4me@yahoo.com

  • Guest
PHP Script Development
« on: April 12, 2010, 07:42:29 am »
I've written a simple script to convert UTF-8 names to English characters.  When sorting by translated names, the result is that Carré Otis is converted to carre otis.   Note that the é is converted to e and the name is converted to lower case.  When sorting by TRANSNAME, this results in a display similar to Windows Explorer.

Unfortunately, this is strictly an English-language translation.  It's my only language.  I've tried many times to learn other languages and failed.  Kudos to those of you who can speak in multiple languages !!!  At any rate, the script is simple enough that I think (hope) that others can make this work for their own region.

There a couple of things that need to happen for this to work.

1) install PHP (CLI VERSION) with interbase (no server is necessary...it's one of the things you're asked during install)
    http://ca2.php.net/get/php-5.2.13-win32-installer.msi/from/a/mirror is the install link (windows)
2) be sure that the .php extension is registered to the php.exe program.  This is an option for install, but you may have to do this
    manually by right-clicking your mouse on the transname.php file and setting the default program to c:\program files\php\php.exe
3) copy the fbembed.dll file from the PVD directory to the php directory and RENAME IT to gds32.dll
4) copy the following dlls from the pvd directory to the php directory
    - icudt30.dll
    - icuin30.dll
    - icuuc30.dll
5) in the script, you need to enter the exact path and database file name...the place in the script I think is obvious, but let
    me know and I'll help out
6) make sure PVD is NOT running, then double-click the transname.php file.
7) a command window should open, and the record number that is being updated should be displayed...about 1000 names per second.

I'm sure Nostra has something like this up his sleeve (watch him if you play cards with him), but until he pulls it out, this should work.  As they say, if you go to a card game and don't see a looser, you're it.

If you're observant, you'll see there's a metaphone option (set to false) in the script.  I'm hoping (someday) to use this to find people or titles on the internet without regard to spelling or the order of names (ie. A.J. COOK or COOK, A.J. or a.j. cooke).  Not to worry...it's still in the dreaming stage.  It never hurts to be ready.

This is the first of a number of 'general purpose' scripts I'll be posting.  I'm really fond of ImageMagik as well, and will probably be posting image manipulation scripts in the near future.  This is a program that can manipulate images, and do significant 'intelligent' processing.  Of course, it's another install, but that's later.

I'm still working on a way to integrate this into PVD, so someday, such scripts may run directly from PVD.

Screenshots of the php installation settings:



[attachment deleted by admin]
« Last Edit: April 13, 2010, 10:32:28 pm by mgpw4me@yahoo.com »

Offline rick.ca

  • Global Moderator
  • *****
  • Posts: 3241
  • "I'm willing to shoot you!"
    • View Profile
Re: Sorting (English) names
« Reply #1 on: April 12, 2010, 11:22:55 am »
Doesn't work for me. A command window opens and immediately closes. :(

Do you see anything awry in the attached screen shot?

[attachment deleted by admin]

mgpw4me@yahoo.com

  • Guest
Re: Sorting (English) names
« Reply #2 on: April 12, 2010, 04:33:41 pm »
If you open a command window, and go to the directory transname is installed in and type transname.php it will display the messages that are causing it not to work.  It might be that the path to the db is not correct (in the script) or that there is a library missing (maybe I forgot something).

directory path commands:

cd \                            go to root
cd ..                           go up one directory level
cd directory_name         go to directory (must be the current hierarchy level).

Offline rick.ca

  • Global Moderator
  • *****
  • Posts: 3241
  • "I'm willing to shoot you!"
    • View Profile
Re: Sorting (English) names
« Reply #3 on: April 12, 2010, 07:05:39 pm »
No, I tried that. There are no error messages. It's like it's not even starting.

I don't know if it should make any difference, but I stopped Firebird Server while trying this. Could there be a problem because this is installed?

mgpw4me@yahoo.com

  • Guest
Re: Sorting (English) names
« Reply #4 on: April 12, 2010, 09:19:53 pm »
The lack of messages is a good thing.  Database connections, scripting errors, missing libraries or php configuration issues would all cause messages.

My SQL statement merely checked for transname = ''...sound familiar?  Null / not null ?  Since you haven't set the transname to a value, it must be null and the sql statement didn't find any '' values, so it exited.  I've been messing with this for a week or two now, so all my transname values have been set several times, hence it worked properly for me.

I've updated the script and reloaded the zip file.

Offline rick.ca

  • Global Moderator
  • *****
  • Posts: 3241
  • "I'm willing to shoot you!"
    • View Profile
Re: Sorting (English) names
« Reply #5 on: April 13, 2010, 01:59:31 am »
It still doesn't work. The behaviour is exactly the same as before. ???

mgpw4me@yahoo.com

  • Guest
Re: Sorting (English) names
« Reply #6 on: April 13, 2010, 03:20:02 am »
Simple test script:

<?php
 phpinfo();                                                                            
?>

Save this in a file (ie. test2.php) and run it.  It should send many lines of php configuration information...indicating php is working properly.

I've added some print statements to send messages at important points in the transname script and re-upped it.  Run it from a command prompt and let me know what messages come up.

If you still don't get any messages, then I'd have to assume that the php extension is not properly associated with the php.exe program. From a command prompt, go to the directory where you have php.exe installed and enter:
php.exe transname.php
« Last Edit: April 13, 2010, 03:30:50 am by mgpw4me@yahoo.com »

Offline rick.ca

  • Global Moderator
  • *****
  • Posts: 3241
  • "I'm willing to shoot you!"
    • View Profile
Re: Sorting (English) names
« Reply #7 on: April 13, 2010, 03:59:32 am »
The test script produced the php config info, but still the same results from transname.php. I guess it's not even getting to the first echo statement. So is it failing to connect? Are you sure this "ibase" function (I have no idea what it is) is compatible with my Firebird Server installation? Also, I found it odd your demo database path started with "C:\\\", but I've used both that and "C:\" with the same result.

Offline rick.ca

  • Global Moderator
  • *****
  • Posts: 3241
  • "I'm willing to shoot you!"
    • View Profile
Re: Sorting (English) names
« Reply #8 on: April 13, 2010, 05:29:20 am »
Nice try. You realize, of course, I get the notification—even if you delete the post. Your debugging (batting?) skills are being tested. Tick-tock... ;D

mgpw4me@yahoo.com

  • Guest
Re: Sorting (English) names
« Reply #9 on: April 13, 2010, 05:35:14 am »
I can run firebird server at the same time as the script runs.  The script uses the embedded dll (fbembed.dll).  If you start PVD and then run the script, you'll see connection errors and the script will fail...or at least, that's what should happen.

I just uninstalled php on my machine, reinstalled, copied fbembed over and everything works.

The database path works on my system with c:\\\ and c:\.  The \\\ ends up being \\ when the code is actually executed.

Some further testing...you have 2 choices.
1) add the PVD directory to your environment path variable ( control panel -> system -> Advanced system settings -> environment variables
2) copy the following dlls from the pvd directory to the php directory
    - icudt30.dll
    - icuin30.dll
    - icuuc30.dll

Once the dlls are 'available', transname should work.  Strange you wouldn't get errors from this...I did.

The reason things worked after my reinstall is that I used option #1 (add pvd to path variable)...which I'd actually recommend...it maintains compatibility with  updates of PVD.
« Last Edit: April 13, 2010, 05:40:57 am by mgpw4me@yahoo.com »

mgpw4me@yahoo.com

  • Guest
Re: Sorting (English) names
« Reply #10 on: April 13, 2010, 05:35:38 am »
Nice try. You realize, of course, I get the notification—even if you delete the post. Your debugging (batting?) skills are being tested. Tick-tock... ;D

Zing !!!

Offline rick.ca

  • Global Moderator
  • *****
  • Posts: 3241
  • "I'm willing to shoot you!"
    • View Profile
Re: Sorting (English) names
« Reply #11 on: April 13, 2010, 07:42:23 am »
Still doesn't work. :'(

mgpw4me@yahoo.com

  • Guest
Re: Sorting (English) names
« Reply #12 on: April 13, 2010, 07:49:26 am »
same thing if you run:

php.exe transname.php

from a command window??

Offline rick.ca

  • Global Moderator
  • *****
  • Posts: 3241
  • "I'm willing to shoot you!"
    • View Profile
Re: Sorting (English) names
« Reply #13 on: April 13, 2010, 10:20:40 am »
Look, matey, I know a dead parrot when I see one, and I'm looking at one right now.

Offline CAD

  • Older Power User
  • *****
  • Posts: 168
  • I've got my eye on you!
    • View Profile
Re: Sorting (English) names
« Reply #14 on: April 13, 2010, 02:28:41 pm »
its not dead - its just sleeping
three fingered salutation

mgpw4me@yahoo.com

  • Guest
Re: Sorting (English) names
« Reply #15 on: April 13, 2010, 04:40:02 pm »
Pining for the fjords?

I have this magic pillow I put my head on and it drains all the clutter.  I did that last night and when I awoke...rick.ca was still not working.  This makes sense since he's the tester and not necessarily the 'follow it to the letter' guy.  'nuf on that.

Fix #...30 or 40?  

No messages = wrong php installation
script exits immediately = path to database wrong or interbase not installed

Time to check your install, Rick.ca.  Go into the control panel -> programs and features.  Find PHP and right-click your mouse on it...in the menu that appears, select CHANGE.

First, change your install type from SCRIPTING to CLI.  This will fix the lack of messaging (the scripting install is for background processes that do not use messaging or open command windows).

Next, scroll down to the extensions section and enable interbase.

This was step #1 in my install instructions, but ("HELLO POLLY !!!") since I've done this several times I skimmed over it without much explanation, thinking it was obvious.  I've added an image to the install instructions to clarify this.

Now that the install is correct, the script will work (be sure not to CANCEL out of the install... :)).  NOTE:  gds32.dll will be overwritten, I think, so make sure to copy fbembed.dll from PVD into the PHP directory and rename it to gds32.dll.

If this doesn't work, post your php.ini for me.
« Last Edit: April 13, 2010, 04:54:49 pm by mgpw4me@yahoo.com »

Offline rick.ca

  • Global Moderator
  • *****
  • Posts: 3241
  • "I'm willing to shoot you!"
    • View Profile
Re: Sorting (English) names
« Reply #16 on: April 13, 2010, 08:53:44 pm »
Quote
First, change your install type from SCRIPTING to CLI.  This will fix the lack of messaging (the scripting install is for background processes that do not use messaging or open command windows).

I don't have this option—see screen shot. You're using an earlier version. It doesn't appear to make any difference anyway. Following is the result of php.exe -v...

Code: [Select]
PHP 5.2.13 (cli) (built: Feb 24 2010 14:32:32)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2010 Zend Technologies

Quote
script exits immediately = path to database wrong or interbase not installed

Yes, it works better with interbase installed. I thought "install PHP with interbase" is what the referenced installation did, not an instruction to "install PHP without the server and with the option to include interbase." ::)

So now the database is accessed and the script runs...

Code: [Select]
database connected
creating sql update statements
ready to run updates
30356 records to be updated...here we go
0 1 2 3...

...and that's the number of people in my database. Unfortunately, only the names having no accented/special characters are written to Transname. :(

[attachment deleted by admin]

mgpw4me@yahoo.com

  • Guest
Re: Sorting (English) names
« Reply #17 on: April 13, 2010, 10:31:41 pm »
I was getting tired and making changes to the script trying to get it working...all the while having no idea why it wasn't working.  So of course, I broke it in the process.

I've uploaded a new version with database checking and logic to update only records without a transname setting.  I'm going to use this thread for testing new scripts and set up a "clean" thread for working scripts.
« Last Edit: April 13, 2010, 10:33:13 pm by mgpw4me@yahoo.com »

Offline rick.ca

  • Global Moderator
  • *****
  • Posts: 3241
  • "I'm willing to shoot you!"
    • View Profile
Re: PHP Script Development
« Reply #18 on: April 13, 2010, 10:54:51 pm »
Quote
I was getting tired and making changes to the script trying to get it working...all the while having no idea why it wasn't working.  So of course, I broke it in the process.

If I didn't know better, I'd think you were not having fun. I believe you meant to say...

"Yeah! You stunned him, just as he was wakin' up! Norwegian Blues stun easily, major."

Now it works. ;)

mgpw4me@yahoo.com

  • Guest
Re: PHP Script Development
« Reply #19 on: April 13, 2010, 11:09:13 pm »
Let's just say I can smile about it...now.

 

anything