Blog Ronald

Welcome to my Blog

Archive for the ‘PHP’ Category

Connect Zend Framework with Oracle XE

Posted by T. Ronald S. on November 27, 2009

Howdy,
As a new player in zend framework, i tried to connect my php with oracle using Zend_Db and tried to get sysdate from oracle. Here how it goes.
First i created a DB.php file and put it in models directory

<?php
require_once 'Zend/Db.php';
class DB{

    protected $db = null;

    function __construct(){
        $params = array('username'=>'user','password'=>'pass','dbname'=>'//localhost/XE');
        $this->db = Zend_Db::factory('oracle',$params);
    }

    function getSysDate(){
        $res = $this->db->fetchRow("select sysdate as coldate from dual");
        return $res['COLDATE'];
    }
    function helloWorld(){
        return 'Hello World';
    }
}
?>

and then i modified the indexController.php as below

<?php
require_once 'models/DBphp';
class IndexController extends Zend_Controller_Action
{
    protected $db;
    public function init()
    {
        $this->_helper->viewRenderer->setNoRender();
        $this->db = new DB();
    }

    public function indexAction()
    {
        echo $this->db->helloWorld();
        echo $this->db->getSysDate();
    }
}

Run and it displayed
Hello World 28-NOV-09

Nice, next i will try to connect php with my java webservice modules. See yaa!

Posted in PHP | Leave a Comment »

Fix error when creating action in Zend Framework

Posted by T. Ronald S. on November 27, 2009

Fatal error: Call to undefined function token_get_all() in
…/ZendFRamework/library/Zend/ReflectioN/File.php on line 300

The error message happened because we haven’t enabled the tokenizer extention in PHP. To enable that extension simply do this:

- open your php.ini, uncomment this line
before:
#extension=tokenizer.so
after:
extension=tokenizer.so

- save your php.ini and restart apache
- try to create a project and an action
$ zf.sh create project testing
$ cd testing
$ zf.sh create action testaction index

you will have your testaction created. Hope this is helpful

Posted in PHP | Leave a Comment »

Install LAMP on ubuntu

Posted by T. Ronald S. on April 24, 2009

Lately I’ve been using ubuntu 7.10 for all my projects/daily work.
As a web developer i should have LAMP on my machine and now i would guide you through installing it on yours.

This guide is divided into 3 steps: installing/tesing Apache, PHP and finally MySQL.

Lets start with Apache:
1. Open the terminal (we will be using it through most of my guide) from Applications > Accessories > Terminal
2. Install apache2 using apt-get by typing the following

sudo apt-get install apache2

Note that you should know the root password.

Now everything should be downloaded and installed automatically.
To start/stop apache2 write:

sudo /etc/init.d/apache2 start
sudo /etc/init.d/apache2 stop

Your www folder should be in: /var/www/

If everything is OK you should see an ordinary HTML page when you type: http://localhost in your firefox browser

Finished with Apache ? lets conquer PHP:

1. Also in terminal write:

sudo apt-get install php5 libapache2-mod-php5

or any php version you like
2. restart apache

sudo /etc/init.d/apache2 restart

This is it for PHP :D Wanna test it ? Just create an ordinary PHP page in /var/www/ and run it.

Example:

sudo gedit /var/www/test.php

and write in it: < ?php echo “Hello World”; ?>

Now run it by typing http://localhost/test.php in firefox… You should see your ” Hello World ”

66 % is over, lets continue to installing MySQL:
1. Again and again in terminal execute:

sudo apt-get install mysql-server

2. (optional) If you are running a server you should probably bind your address by editing bind-address in /etc/mysql/my.cnf and replacing its value (127.0.0.1) by your IP address
3. set your root password (although mysql should ask you about that when installing)

mysql> SET PASSWORD FOR ‘root’@’localhost’ = PASSWORD(’xxxxxx’);

4. Try running it

mysql -uroot -pxxx

where xxx is your password.
Note: You can install PHPMyAdmin for a graphical user interface of MySQL by executing

sudo apt-get install libapache2-mod-auth-mysql php5-mysql phpmyadmin

5. restart apache for the last time

sudo /etc/init.d/apache2 restart

Congratulions your LAMP system is installed and running :D Happy Coding

//Jo

UPDATE:
Due to the large number of people emailing about installing/running phpmyadmin.
Do the following:

sudo apt-get install phpmyadmin

The phpmyadmin configuration file will be installed in: /etc/phpmyadmin
Now you will have to edit the apache config file by typing

sudo vi /etc/apache2/apache2.conf

and include the following line:

Include /etc/phpmyadmin/apache.conf

Restart Apache

sudo /etc/init.d/apache2 restart

Another issue was making mysql run with php5
First install these packages:

sudo apt-get install php5-mysql mysql-client

then edit php.ini and add to it this line : ” extensions=mysql.so” if it isnt already there

sudo vi /etc/php5/apache2/php.ini

Restart Apache

sudo /etc/init.d/apache2 restart

Hope this helps :)

Share and Enjoy:

Posted in PHP | 2 Comments »