Friday, July 28, 2006

Refreshing Zend Framework from the SVN Tree

This is a short writeup regarding using SmartSVN, a Subversion client for checking out the latest code for Zend's PHP Framework. Also serves as a useful introduction to using SmartSVN. This article was posted in Chinese a couple of weeks back by Joe, and here's the same in English.

1. Getting the Subversion Client
To get the latest code for Zend Framework, use a Subversion (SVN) client like SmartSVN.

Download the latest SmartSVN Subversion client from http://www.syntevo.com/smartsvn/index.jsp

2. Creating a Profile for Zend's SVN Trunk

After installing the client, go to Repository -> Manage Profiles, to add a new profile which links to Zend's SVN repository.



Click Add, and then "Enter SVN Url...", that should show the SVN URL dialog box.

Key in the following URL: http://framework.zend.com/svn/framework/trunk

The client will automatically segment the URL appropriately.

repositoryProfile

Key in a name for the profile name, in this case, "Zend Framework".

TIP: Remember to go to the proxy tab to update your proxy settings, if you are behind the firewall.

manageProfiles_proxy

That's it, the profile for Zend Framework's SVN tree is created.

3. Checking out Zend Framework Project from SVN

To check out the entire Zend Framework tree, do the following.

Go to Project->Check Out

checkout

Under Respository Profile, choose "Zend Framework", which is the one we just created.

checkout_repo

Click Next. The directory scanning will start.

This is what you will see, let it be default, so that the client can get everything.

checkout_source

Click Next.

checkout_target

Select a target directory for the source files that will be checked out.

Click Next, choose a Project Name. Make sure the "Add to list of managed projects" checkbox is checked.

checkout_name

Go to Confirmation, and click Finish.

The entire process is completed, the latest source will be checked out from Zend's SVN tree to your target directory.

4. Updating your tree.
Updating your tree allows you to get the latest release of Zend Framework without waiting for the official release.

Right-click on the project name, and click "update".

The revision number will change once the source tree is updated.

update

Wednesday, July 26, 2006

Chris at OSCON Portland 2006

Christopher Jones will be speaking at OSCON Portland 2006, so if you are lucky enough to be there, go say Hi! :)

There will be 3 Oracle related talks at OSCON, but you can read about them over at Chris' blog.

Thursday, July 20, 2006

Install and Configure PHPUnit2 for Zend Framework

Similar to JUnit for Java, PHPunit2 is a sophisticated testing tool for PHP. In this article I would like to introduce how to run PHPUnit2 for Zend Framework

1 Install Zend Framework
Zend Framework is available at http://framework.zend.com/download , from where you can get .zip or .tar.gz file. Unzip(or Untar) the file you just downloaded to directory ZendFramework-x.x.x. Then copy the Zend subfolder and Zend.php which are in ZendFramework-x.x.x\library to the directory indicated by “include_path” of the php.ini file. At this time, you can use require_once “xxx.php” to use the classes in Zend Framework.

2 Install PEAR (on Windows)
PEAR is short for "PHP Extension and Application Repository. As PHPUnit2 is recommended to be installed via PEAR installer, we should install PEAR first. There is an easy way to install PEAR, request http://go-pear.org/ in your browser and save the output to a local file go-pear.php. Then You can then run php go-pear.php in a Windows Command Prompt to start the installation or PEAR update process.

Here is a trick. When run php go-pear.php, PEAR will be downloaded and updated online. Sometimes we can’t connected to the server, if this happens set the proxy to http://xxx.com:80 instead of http://xxx.com since PEAR is not clever enough to consider http://xxx.com to be http://xxx.com:80.

Install PHPUnit2: (on Windows)
PHPUnit2 is available from the http://pear.php.net/, which is a framework and distribution system for reusable PHP components. It can be installed using the PEAR Installer, as shown in the following example: pear install PHPUnit2.

If this fails, you can copy the PHPUnit2-x.x.x.tgz file that you downloaded to the folder where you want it to be installed. Now issue the following command: pear install PHPUnit2-x.x.x.tgz.. After installation you should be able to find the PHPUnit2's source files inside your PEAR local directory.

Do remember to install the two packages that PHPUnit2 depends on: Benchmark and Console_Getopt before installing PHPUnit2.

3 Run PHPUnit2 for Zend Framework.
After the 3 steps, we can start running test cases for Zend Framework now. There are some unit tests that comes with Zend Framework in the subfolder ZendFramework_Dir\tests. Let's use ZendTest?.php for our example. You can also write your own cases for your code.

Copy ZendTest?.php to the directory which is indicated by “include_path” in php.ini. Then you can run "phpunit ZendTest?"

The following is the result:

PHPUnit 2.3.6 by Sebastian Bergmann.

EF.E.EF....

Time: 0.021509 There were 3 errors: 1) testLoadClassValid(ZendTest?) File "D:\www\Zend\_files\_testDir1\Class1.php" was not found. D:\www\Zend.php:87 D:\www\ZendTest.php:34 2) testLoadClassSearchDirs(ZendTest?) File "D:\www\Zend\_files\_testDir2\Class1.php" was not found. D:\www\Zend.php:87 D:\www\ZendTest.php:78 3) testLoadInterfaceValid(ZendTest?) File "D:\www\Zend\_files\_testDir1\Interface1.php" was not found. D:\www\Zend.php:131 D:\www\ZendTest.php:103 There were 2 failures: 1) testLoadClassNonexistent(ZendTest?) "File "D:\www\Zend\_files\_testDir1\ClassNonexistent.php" was not found." does n ot match pattern "/file(.*)loaded but class(.*)not found/i" D:\www\ZendTest.php:48 2) testLoadInterfaceNonexistent(ZendTest?) "File "D:\www\Zend\_files\_testDir1\ClassNonexistent.php" was not found." does n ot match pattern "/file(.*)loaded but interface(.*)not found/i" D:\www\ZendTest.php:117

FAILURES!!! Tests run: 11, Failures: 2, Errors: 3, Incomplete Tests: 0.

Friday, July 07, 2006

Install & Configure Apache+PHP+ZendFramework+OracleDbXe On Windows In Minutes

Let's say you want to install Apache+PHP+ZendFramework+OracleDbXe (Oracle Database Express Edition)
and play around with the spanky new Zend Framework made available by the folks over at Zend Corporation.
It's actually quite easy and painless.

This article gives you a easy and practical guide to installing,
configuring and testing Apache2.2.2+PHP5.1.4
+ZendFramework0.1.4+OracleDb10gXe10.2.0.1.0 on Windows OS.
Set up your development environment with Zend Framework in minutes!

1. Download and Install the S/Ws.
(1) Download OracleDb10gXe10.2.0.1.0 from http://otn.oracle.com and
install it.
(2) Then use the command “sqlplus / as sysdba” to
connect to the db, and execute “alter user hr account
unlock” to unlock the user “hr”.
(3) Download Apache2.2.2 from http://www.apache.org and install it.
E.g, install it at C:\Programs\Apache2.2.
(4) Download PHP5.1.4 from http://www.php.net and install it. E.g.,
install it at C:\Programs\php-5.1.4-Win32.
(5) Download ZendFramework0.1.4 from http://framework.zend.com and
install it. E.g, install it at C:\Programs1\ZendFramework-0.1.4.

2. Configure Apache and PHP.
(1) Make sure you have a folder for your website, e.g.,
C:\ProgDemo\WebSiteDemo.
(2) Setup the Apache conf file C:\Programs\Apache2.2\conf\httpd.conf as
follows:
21) DocumentRoot "C:/ProgDemo/WebSiteDemo"
22) <Directory "C:/ProgDemo/WebSiteDemo">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
23) <Directory "C:/Programs/php-5.1.4-Win32">
AllowOverride All
Order allow,deny
Allow from all
</Directory>
24) DirectoryIndex index.html index.php
25) ScriptAlias /php/ "C:/Programs/php-5.1.4-Win32/"
26) AddType application/x-httpd-php .php
27) Action application/x-httpd-php "/php/php-cgi.exe"
SetEnv PHPRC "C:/Programs/php-5.1.4-Win32"
(3) Rename the PHP config file C:\Programs\php-5.1.4-Win32\php.ini-dist
to C:\Programs\php-5.1.4-Win32\php.ini. Then setup the
file php.ini as follows:
31) include_path = ".;C:\Programs1\ZendFramework-0.1.3\library"
32) doc_root = "C:\ProgDemo\WebSiteDemo"
33) extension_dir = "./ext"
34) extension=php_oci8.dll

Ok, everything is installed, just a couple more steps to tie them up. :)

3. Test operating OracleDbXe via PHP and Zend Framework.
(1) Create a file named “index.php” in the folder
C:\ProgDemo\WebSiteDemo.
(2) Edit the file “index.php” as follows:
<?php print
"This is a Demo that PHP operates OracleDB10gXe via PHP Plus Zend
Framework!<br><br>\n" ?>

<?php
require_once 'Zend/Db.php';
$params = array ('host'=>'localhost','username'=>'hr','password'=>'hr','dbname'=>'xe');
$db=Zend_Db::factory('Oracle', $params);
$querysql = 'select last_name, salary from employees where salary > 11000';
$result = $db->query($querysql);
$rowset = $result->fetchAll();
$n=max(count($rowset["LAST_NAME"]),count($rowset["SALARY"]));
print '<table border="1"><tr><td>Name</td><td>Salary</td></tr>';
for($i=0;$i<$n;$i++)
{
print "<tr><td>".htmlspecialchars($rowset["LAST_NAME"][$i])."</td><td>".htmlspecialchars($rowset["SALARY"][$i])."</td></tr>";
}
?>
(3)Key in http://localhost and you will see the results of your query, which goes through Zend libraries.

Viola! :)

Do let us have your comments.

Install & Configure Apache+PHP+OracleDbXe On Windows In Minutes

If you think installing Apache+PHP+OracleDbXe (Oracle Database Express Edition) is complicated, think no more. This article gives you some simple steps to installing, configuring and testing Apache2.2.2+PHP5.1.4+OracleDb10gXe10.2.0.1.0 on Windows OS. Your development environment can be set up within minutes.

Software Versions:
1. Apache 2.2.2
2. PHP 5.1.4 Oracle
3. DB 10g XE ( 10.2.0.1.0 )

1. Download and Install the S/Ws.
(1) Download OracleDb10gXe10.2.0.1.0 from http://otn.oracle.com/ and install it.
(2) Then use the command “sqlplus / as sysdba” to connect to the db, and execute “alter user hr account unlock” to unlock the user “hr”.
(3) Download Apache2.2.2 from http://www.apache.org/ and install it. E.g, install it at C:\Programs\Apache2.2.
(4) Download PHP5.1.4 from http://www.php.net/ and install it. E.g., install it at C:\Programs\php-5.1.4-Win32. Alright, at this point, everything is installed, let's tie them up!

2. Configure Apache and PHP.
(1) Make sure you have a folder for your website, e.g., C:\ProgDemo\WebSiteDemo.
(2) Setup the Apache conf file C:\Programs\Apache2.2\conf\httpd.conf as follows:
21) DocumentRoot "C:/ProgDemo/WebSiteDemo"
22) <Directory "C:/ProgDemo/WebSiteDemo">
Options Indexes FollowSymLinks
AllowOverride None
Order allow,deny
Allow from all
</Directory>
23) <Directory "C:/Programs/php-5.1.4-Win32">
AllowOverride All
Order allow,deny
Allow from all
</Directory>
24) DirectoryIndex index.html index.php
25) ScriptAlias /php/ "C:/Programs/php-5.1.4-Win32/"
26) AddType application/x-httpd-php .php
27) Action application/x-httpd-php "/php/php-cgi.exe"
SetEnv PHPRC "C:/Programs/php-5.1.4-Win32"
(3) Rename the PHP config file C:\Programs\php-5.1.4-Win32\php.ini-dist to C:\Programs\php-5.1.4-Win32\php.ini. Then setup the file php.ini as follows:
31) doc_root = "C:\ProgDemo\WebSiteDemo"
32) extension_dir = "./ext"
33) extension=php_oci8.dll

That's it! Let's run some test so you can sleep easy.

3. Test operating OracleDbXe via PHP.
(1) Create a file named “index.php” in the folder C:\ProgDemo\WebSiteDemo.
(2) Edit the file “index.php” as follows:
<?php print"This is a Demo that PHP operatesOracleDB10gXe!<br><br>\n" ?>
<?php
$conn = oci_connect('hr','hr','//localhost:1521/xe');
$query = 'select last_name, salary from employees where salary > 11000';
$stid = oci_parse($conn, $query);
$r = oci_execute($stid, OCI_DEFAULT);
print '<table border="1"><tr><td>Name</td><td>Salary</td></tr>';
while($row = oci_fetch_array($stid, OCI_RETURN_NULLS))
{
print '<tr>';
foreach ($row as $item)
{
print '<td>'.($item?htmlentities($item):' ').'</td>';
}
print '</tr>';
}
print '</table>';
oci_close($conn);
?>
(3)Key in http://localhost in your browser and you will see the output of your query from OracleDbXe.

Tada! :)

Do let us have your comments.