Flex with PHP using ZendAMF – Zend_Db

In articler Adobe Flex with PHP using ZendAMF – first steps aimed to illustrate the integration of Flex with PHP for those who had already developed systems using AMFPHP, so I did not use the classes to access database ZendFramework. In this article show the same example but using only ZendFramework.

I will take the same example used in the previous article, just changing the class to use PHP classes abstraction database ZendFramework. We begin with our gateway.php

[PHP]
setProduction(false);
$server->setClass(‘Contato’);
echo($server->handle());
?>
[/PHP]

Running the link into your browser, you should see the following message:

Zend Amf Endpoint

Then modify in our main class, which will perform the operations list, insert, delete and update data from our database:

[PHP]
config = new Zend_Config($data);
$this->db = Zend_Db::factory($this->config->database);
}

public function getData()
{
try
{
$this->select = $this->db->select();
$this->select->from(‘tabela’,array(‘id’,’nome’,’email’));
$this->stmt = $this->select->query();
$result = $this->stmt->fetchAll();
return $result;
}
catch (Exception $e)
{
throw new Exception($e->getMessage());
}
}

public function insertData($data=array())
{
try
{
$dados = array(
‘nome’ => $data[‘nome’],
’email’ => $data[’email’]
);
$retorno = $this->db->insert(‘tabela’, $dados);
return $retorno;
}
catch (Exception $e)
{
throw new Exception($e->getMessage());
}
}

public function deleteData($data=array())
{
try
{
$retorno = $this->db->delete(‘tabela’, ‘id = ‘.$data[‘id’]);
return $retorno;
}
catch (Exception $e)
{
throw new Exception($e->getMessage());
}

}

public function updateData($data=array())
{
try
{
$dados = array(
‘nome’ => $data[‘nome’],
’email’ => $data[’email’]
);
$where[‘id = ?’] = $data[‘id ‘];
return $this->db->update(‘tabela’, $dados, $where);
}
catch (Exception $e)
{
throw new Exception($e->getMessage());
}
}

}
?>
[/PHP]

In ActionScript only need to change what will be passed to PHP, instead of VOs, send Arrays:
[ACTIONSCRIPT3]
public function insertData():void
{
var contatosVO:Array = [];
contatosVO[‘nome’]= input_nome.text;
contatosVO[’email’] = input_email.text;
ro.insertData(contatosVO);
}
[/ACTIONSCRIPT3]

Reference:
http://framework.zend.com/manual/en/zend.db.adapter.html

Buy the source code $4.99 – include php, mxml and sql.
[paid-downloads id=”2″]

More source and PDFs click here

Was this article helpful? feel free to make a donation and help keep the blog in the air
Flex, PHP, ZendAMF

Leave a Reply