Home > centOS, Fedora 12, MySQL, PHP, Unix/Linux, Zend > Zend zend_db sql mysql

Zend zend_db sql mysql

How to zend sql?

1. Free hand SQL, make it FREE!

<?php

class IndexController extends Zend_Controller_Action

{

public function init()

{

// Instant db access

$db = Zend_Db::factory(‘Pdo_Mysql’,

array(

‘host’ => ‘localhost’,

‘username’ => ‘root’,

‘password’ => ‘00000’,

‘dbname’ => ‘myzf’

));


// SQL

$sql =

SELECT

id,

name,

status

FROM

myzf

;

// Submit <> get

$rows = $db->fetchAll($sql);

// Put query in session

$this->mysession = new Zend_Session_Namespace(‘mysession’);

$this->mysession->one =$rows;

// Simuate the result we can use from VIEWS

echo ‘<pre>’;

print_r($this->mysession->one);

echo ‘</pre>’;

}

public function indexAction()

{

}

public function addAction()

{

}

public function editAction()

{

}

public function delAction()

{

}

public function listAction(){

}

}

2. Output


Array

(
    [0] => Array
        (
            [id] => 1
            [name] => ada
            [status] => top
        )

    [1] => Array
        (
            [id] => 2
            [name] => c
            [status] => second
        )

    [2] => Array
        (
            [id] => 3
            [name] => java
            [status] => third
        )

)
Advertisements
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: