Zend error
4 answers
Do you have any knowledge of working with databases in PHP? you should definitely start there before going into the framework. Once you have a basic understanding of how PHP and databases interact, moving to a good framework like Zend shouldn't be too difficult.
The Zend Framework manual has a fairly detailed overview of everything it can do with databases .
+5
source to share
/ Insert / / ** * I'm assuming you are passing data through a 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 the md5 function is not secure enough, you might want to look for the bcrypt hashing algorithm. Here is a link to the same: http://framework.zend.com/manual/current/en/modules/zend.crypt.password.html
+5
source to share
/**
*
*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;
+2
source to share