Thursday, June 21, 2007

PHP SYMFONY (a.k.a. Have you seen my CRUD?)

OK, so I looked at RoR and had some fun; now a headlong excursion into the YAML-y goodness of PHP Symfony. http://www.symfony-project.com

10:08 PM
Forgive me if I seem short tempered...I hurt my back this week, and it is excruciating. So I will tolerate very little from the gods of software in terms of framework lunacy. Either it works or it doesn't!

10:09 PM
Downloaded Symfony already ( http://www.symfony-project.com/get/symfony-stable.tgz ).
Then went to the My First App. RTFM? Ha!

10:10 PM
http://www.symfony-project.com/tutorial/my_first_project.html
OK, so I tried downloading the tgz. Uh, seems broken, guys. OK, well I'm sure my web sites have broken links. Fair enough.

10:11 PM
Found the sandbox on the download page. http://www.symfony-project.com/get/sf_sandbox.tgz

Unpacking....done. Gee, I hope it doesn't care that my Apache2 is in Program Files....spaces seem to stymie the open source folks. I guess that is for commercial apps only.

10:14 PM
http://localhost/sf_sandbox/web/index.php/
Great. Ugly URL, I guess they don't expect to use it for anything consumer oriented. OK, I won't rant on this again. Now what...reate a schema.yml file in sf_sandbox/config/ oh, YAML-icious!! Just what I need....ANOTHER way to screw up my app with an extra whitespace. Hooray! Thanks! Did I mention before that I was pre-Med in college? What was I thinking getting into software....

Anyhow...

10:17 PM
C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\sf_sandbox>C:\php\p
hp.exe symfony propel-build-model
PHP Warning: PHP Startup: Unable to load dynamic library './php_pdo.dll' - The
specified module could not be found.
in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library './php_pdo_sqlite.dll'
- The specified module could not be found.
in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library './php_sqlite.dll' - T
he specified module could not be found.
in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library './php_xsl.dll' - The
specified module could not be found.
in Unknown on line 0

Yeah, I could have predicted that. OK, so maybe my PATH variable isn't set with c:\php correctly. fine fine fine!

10:25 PM
OK, well PHP's install set the wrong ext dir for Win32 (I know, I know....USE UNIX). OK, tangent here: I TRIED using SuSe Linux first! Apache wouldn't install! Ha! So, as much as I love *Nix and BSDs, sadly, if everything looks like a nail...

10:32 PM
Well, these Base* classes seem interesting. Guess it's time to look at exactly what propel is (I remember it when I looked at ORM for PHP awhile back, but for some reason long forgotten I opted for something else.)
http://propel.phpdb.org/trac/

All sounds good. One thing I always look at is the support mail lists. Hmmmm...all told, 5090 posts for Propel. Looking at Hibernate, just for fun, 132K! (And that's ignoring the German and Chinese user forums!) So, either Hibernate really sucks, and Propel is flawless...OR....well, if you want a job as a programmer, DON'T be a PHP (or Ruby or Python) developer. Java just has more jobs. (See related post on Java job counts.) And for those of you who, like me, use offshore engineers...don't even bother with PHP, Ruby, Python. Java may have its limitations, but 1B Chinese and Indian engineers can be a powerful reason to stay!

Of course, if reading my blog doesn't convince you that software engineering is a dead-end job, then I don't know how to help you. I guarantee, if I catch my daughtr within 30 feet of gcc, I'm taking away her stock options...and her pony!

10:43 PM
Back to Symfony.
propel-create-sql --- great. worked like a charm
propel-insert-sql next...

propel > insert-sql:
[propel-sql-exec] Executing statements in file: C:\Program Files\Apache Software
Foundation\Apache2.2\htdocs\sf_sandbox\data\sql\lib.model.schema.sql
[propel-sql-exec] Our new url -> sqlite://./../../../../data/sandbox.db
[propel-sql-exec] Executing file: C:\Program Files\Apache Software Foundation\Ap
ache2.2\htdocs\sf_sandbox\data\sql\lib.model.schema.sql
[propel-sql-exec] Failed to execute:

DROP TABLE [weblog_post]
[propel-sql-exec] Could not execute update [User Info:

DROP TABLE [weblog_post]]
[propel-sql-exec] Failed to execute:


DROP TABLE [weblog_comment]
[propel-sql-exec] Could not execute update [User Info:


DROP TABLE [weblog_comment]]
[propel-sql-exec] 2 of 4 SQL statements executed successfully

BUILD FINISHED

Total time: 1.0381 second
>> file- C:\Program Files\Apache Softwar...box\config\generated-schema.xml

HAHAHAAH. I guess I should have expected that! Well, my back is killing me so I don't have much patience for this now. I will pick this up in the AM when the Advil has done its job. For now, I leave you all with this thought: your finances are in the hands of software 'engineers' who aren't licensed or required to pass any competency review of any kind....good stuff, huh? Well, on that note, I shall ice may spine and drown my sorrows in Isle of Jura. Oh I highly recommend it! TTFN!

NEXT DAY:

1:21 PM
After a fun morning of business, it's time to get down to this PHP business.
Rather than focusing on getting sqllite working, since I am actually interested in prototyping something real, I will try switching to MySQL which is what I will use for my real application, at least as a prototype. This is the last chance, Symfony, else I switch back to Ruby on Rails.

1:23 PM
http://www.symfony-project.com/book/trunk/08-Inside-the-Model-Layer#Database%20Connections

1:40
Getting an error on MySQL:
propel > insert-sql:
[propel-sql-exec] Executing statements in file: C:\Program Files\Apache Software
Foundation\Apache2.2\htdocs\sf_sandbox\data\sql\lib.model.schema.sql
[propel-sql-exec] Our new url -> mysql://foo:bar@localhost/sandbox
Execution of target "insert-sql" failed for the following reason: C:\Program Fil
es\Apache Software Foundation\Apache2.2\htdocs\sf_sandbox\lib\symfony\vendor\pro
pel-generator\build-propel.xml:296:1: [wrapped: connect failed [Native Error: C
an\'t connect to MySQL server on \'localhost\' (10061)] [User Info: Array]]
[phing] C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\sf_sand
box\lib\symfony\vendor\propel-generator\build-propel.xml:296:1: [wrapped: conne
ct failed [Native Error: Can\'t connect to MySQL server on \'localhost\' (10061)
] [User Info: Array]]

BUILD FINISHED

Let me try a simple PHP->MySql on this box, since I haven't done so before (clean install).
.........................................................................
.........................................................................
LATER THAT DAY.......................................

Well, after considerable debugging, including attaching VS to the apache httpd process just to make sure all the right DLLs were getting loaded (no ldd or truss on Win32, although Depends.exe comes in handy in such cases)....I was able to deduce (OK, actualy powers of deduction would have landed me here 4 hours ago...) that my MySQL was running on a non-standard port 3333 for some inane reason. After reading all the posts, and trying untold different experiments, I was able to connect. The trigger? I used a different client tool, Heidi SQL, which failed to connect!! So the cmd line mysql has cached the port. Once Heidi failed, I netstat'd and lo and behold, the solution. Although even after that, I almost shot myself in the foot, cause I was using some bad mysql syntax...unfortunately, PHP didn't give me helpful error messages, so I almost concluded that the port was not the issue, or at least not the only issue. But in the end, I won (if you can call wasting the better part of a beautiful day banging your head against Google "winning"). Med school is looking pretty fun right now...even proctology!

Just FYI - here's my PHP hellow world code that I used to verify basics:

";

// Show all information, defaults to INFO_ALL
phpinfo();

$database = "mysql";

$link = mysqli_connect("localhost", "xxxxx", "yyyyyyy", $database, 3333);

/* check connection */
if (!$link) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}


echo "
    ";
    echo "
  • ".$database;

    // for each database, get table list and print
    $query2 = "SHOW TABLES FROM ".$database;
    $result2 = mysqli_query($link, $query2) or die ("Error in query: $query2. ".mysqli_error());

    echo "
      ";
      while ($row2 = mysqli_fetch_array($result2)) {
      echo "
    • ".$row2[0];
      }
      echo "
    ";

    echo "
";

mysqli_close();

?>

But I digress...onwards and upwards!

10:47 PM (yep, really...ok I had breaks for dinner and story time for the daughter)
Now I can at least, readlly get back to where we were just about 24 hours ago.

propel > insert-sql:[propel-sql-exec] Executing statements in file: C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\sf_sandbox\data\sql\lib.model.schema.sql[propel-sql-exec] Our new url -> mysql://xxxx:yyyyyy@localhost/sandboxExecution of target "insert-sql" failed for the following reason: C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\sf_sandbox\lib\symfony\vendor\propel-generator\build-propel.xml:296:1: [wrapped: mysql extension not loaded [User Info: Array]] [phing] C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\sf_sandbox\lib\symfony\vendor\propel-generator\build-propel.xml:296:1: [wrapped: mysql extension not loaded [User Info: Array]]

OK, well this is true, I enabled mysqli, cause that's what the manual said to!! So, I can enable both (I hope)...

10:52 PM
propel > insert-sql:[propel-sql-exec] Executing statements in file: C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\sf_sandbox\data\sql\lib.model.schema.sql[propel-sql-exec] Our new url -> mysql://xxxxx:yyyyy@localhost/sandbox[propel-sql-exec] Executing file: C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\sf_sandbox\data\sql\lib.model.schema.sql[propel-sql-exec] 6 of 6 SQL statements executed successfully

HOLY GUACAMOLE! And even my hello world (changed the $database="sandbox"):
sandbox
weblog_comment
weblog_post

well. About time!

10:55PM
C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\sf_sandbox>php symfony propel-generate-crud frontend post Post>> dir+ C:\Program Files\Apache Softwar...s/frontend/modules/post\actions>> file+ C:\Program Files\Apache Softwar.../post\actions\actions.class.php>> dir+ C:\Program Files\Apache Softwar...frontend/modules/post\templates>> file+ C:\Program Files\Apache Softwar.../post\templates\editSuccess.php>> file+ C:\Program Files\Apache Softwar.../post\templates\listSuccess.php>> file+ C:\Program Files\Apache Softwar.../post\templates\showSuccess.php>> tokens C:\Program Files\Apache Softwar.../post/actions/actions.class.php>> tokens C:\Program Files\Apache Softwar.../post\actions\actions.class.php>> tokens C:\Program Files\Apache Softwar.../post\templates\editSuccess.php>> tokens C:\Program Files\Apache Softwar.../post\templates\listSuccess.php>> tokens C:\Program Files\Apache Softwar.../post\templates\showSuccess.php>> file+ C:\Program Files\Apache Softwar...al/frontend/postActionsTest.php>> tokens C:\Program Files\Apache Softwar...al/frontend\postActionsTest.php>> file- C:\Program Files\Apache Softwar...oPost\templates\showSuccess.php>> file- C:\Program Files\Apache Softwar...oPost\templates\listSuccess.php>> file- C:\Program Files\Apache Softwar...oPost\templates\editSuccess.php>> dir- C:\Program Files\Apache Softwar...293669c9388e\autoPost\templates>> file- C:\Program Files\Apache Softwar...oPost\actions\actions.class.php>> dir- C:\Program Files\Apache Softwar...68293669c9388e\autoPost\actions>> dir- C:\Program Files\Apache Softwar...73dc2a7d68293669c9388e\autoPost

C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\sf_sandbox>php symfony propel-generate-crud frontend comment Comment>> dir+ C:\Program Files\Apache Softwar...rontend/modules/comment\actions>> file+ C:\Program Files\Apache Softwar...mment\actions\actions.class.php>> dir+ C:\Program Files\Apache Softwar...ntend/modules/comment\templates>> file+ C:\Program Files\Apache Softwar...mment\templates\editSuccess.php>> file+ C:\Program Files\Apache Softwar...mment\templates\listSuccess.php>> file+ C:\Program Files\Apache Softwar...mment\templates\showSuccess.php>> tokens C:\Program Files\Apache Softwar...mment/actions/actions.class.php>> tokens C:\Program Files\Apache Softwar...mment\actions\actions.class.php>> tokens C:\Program Files\Apache Softwar...mment\templates\editSuccess.php>> tokens C:\Program Files\Apache Softwar...mment\templates\listSuccess.php>> tokens C:\Program Files\Apache Softwar...mment\templates\showSuccess.php>> file+ C:\Program Files\Apache Softwar...frontend/commentActionsTest.php>> tokens C:\Program Files\Apache Softwar...frontend\commentActionsTest.php>> file- C:\Program Files\Apache Softwar...mment\templates\showSuccess.php>> file- C:\Program Files\Apache Softwar...mment\templates\listSuccess.php>> file- C:\Program Files\Apache Softwar...mment\templates\editSuccess.php>> dir- C:\Program Files\Apache Softwar...5913509f4\autoComment\templates>> file- C:\Program Files\Apache Softwar...mment\actions\actions.class.php>> dir- C:\Program Files\Apache Softwar...4a5913509f4\autoComment\actions>> dir- C:\Program Files\Apache Softwar...2bad135b4a5913509f4\autoComment

C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\sf_sandbox>php symfony clear-cache>> file+ C:\Program Files\Apache Softwar...cs\sf_sandbox/frontend_prod.lck>> chmod 777 C:\Program Files\Apache Softwar...cs\sf_sandbox\frontend_prod.lck>> file- C:\Program Files\Apache Softwar...he\frontend\prod\config\VERSION>> file- C:\Program Files\Apache Softwar...les_default_config_view.yml.php>> file- C:\Program Files\Apache Softwar...default_config_security.yml.php>> file- C:\Program Files\Apache Softwar...s_default_config_module.yml.php>> file- C:\Program Files\Apache Softwar...efault_config_generator.yml.php>> file- C:\Program Files\Apache Softwar..._default_config_filters.yml.php>> file- C:\Program Files\Apache Softwar...\config\config_settings.yml.php>> file- C:\Program Files\Apache Softwar...d\config\config_routing.yml.php>> file- C:\Program Files\Apache Softwar...\prod\config\config_php.yml.php>> file- C:\Program Files\Apache Softwar...d\config\config_logging.yml.php>> file- C:\Program Files\Apache Softwar...prod\config\config_i18n.yml.php>> file- C:\Program Files\Apache Softwar...config\config_factories.yml.php>> file- C:\Program Files\Apache Softwar...config\config_databases.yml.php>> file- C:\Program Files\Apache Softwar...fig\config_core_compile.yml.php>> file- C:\Program Files\Apache Softwar...\config_config_handlers.yml.php>> file- C:\Program Files\Apache Softwar...onfig_bootstrap_compile.yml.php>> file- C:\Program Files\Apache Softwar...\config\config_autoload.yml.php>> file- C:\Program Files\Apache Softwar...\prod\config\config_app.yml.php>> file- C:\Program Files\Apache Softwar...cs\sf_sandbox/frontend_prod.lck

Seems OK....I guess. Would be nice to know what all that is doing, so I'll want to take a deeper look (after med school). OK, well, of couse something will break and I'll have to look at it sooner than that.

10:58PM
Well, just about 24 hours later, and much scotch, and a bad back to boot...we finally have our CRUD. I am definitely changing careers. This is lunacy. Well, I'm off to make some tea and refresh myself on Organic Chemistry...SN2 baby! It's all about SN2!

Ciao! Zai Jian!

2 comments:

Robert A. Ficcaglia said...

Epilogue
So what was the point? After all this, I suppose we can compare my excursion with Ruby, well RoR, with this exercise. Both gave me a CRUD implementation based off a database schema.

For prototyping something super quick, I would have to day that my experience with PHP was a bit easier, but since I know PHP, that's not a fair comparison. Ultimately, I would expect to use either PHP or Java, or more precisely, I'll be hiring someone who probably doesn't know Ruby! So, from a business perspective, Ruby could be the most beautiful and easy language in the world, but no one knows it who is not already gainfully employed. Any by the time I find someone, we'll have man years of code already done in PHP or Java.

Basically, Java will go away. I see that clearly. But it will take at least 5 or 10 years. Seriously. Look at C/C++; still alive after all these years. VB, too. So, for those fanatics out there, I wish you all the best. But to those of us trying to make stuff work, you use the entire tool box.

gillbates said...

Haha, similar to my own experience starting off with Symfony. Tell it like it is, man.