Reputation:
How I insert my username, Password values to database using Zend framework.
And how I get the values from the database using zend framework.
Upvotes: 0
Views: 544
Reputation: 512
/Insert/ /** * I assume that you are passing data through controller */
class Application_Model_YourModelName extends Zend_Db_Table_Abstract {
private static $_instance = null;
protected $_name = 'YourModelName';
public static function getinstance() {
if (self::$_instance == null)
self::$_instance = new Application_Model_YourModelName();
return self::$_instance;
}
public function insertFunction(){
if(func_num_args()>0){
$userName = func_get_arg(0); // or some index if wanna pass through key value pair
$password = md5(func_get_arg(1));
$data = array('userName'=>$userName, 'password'=>$password);
$insert = $this->insert($data);
}
}
public function fetchFunction(){
$sql = $this->select()
->where("*Your condition*")
;
$result = $this->getAdapter->fetchAll(sql);
}
On the security front using md5 function is not safe enough, u might want to look for bcrypt hashing algorithm.. Here is the link for the same : http://framework.zend.com/manual/current/en/modules/zend.crypt.password.html
Upvotes: 5
Reputation: 99
/**
*
*To insert your values
*
* Here $uname and $password are values dynamically
*/
$db = new Zend_Db(....);
$data = array(
'vUserName'=>$uname,
'vPassword'=>md5($pwd)
);
$db->insert('tablename',$data);
/*
*
*To get the values
*
*/
$sql = "SELECT * FROM <TABLENAME> WHERE vUserName = '".$uname."'";
$data = $db->fetchAll($sql);
return $data;
Upvotes: 2
Reputation: 18196
$db = new Zend_Db(....);
$data = array('username'=>'thomaschaaf', 'password'= md5('secret'));
$db->insert('field', $data);
Upvotes: 0
Reputation: 86805
Do you have any knowledge of working with databases in PHP? you should definitely start there before jumping into frameworks. When you have the basic understanding of how PHP and databases interact, transitioning that into a good framework like Zend's should not be too difficult.
The Zend Framework manual has a pretty comprehensive overview on everything it can do with databases.
Upvotes: 5