English 中文(简体)
改进我的Zentd Stored程序,即《刑法》
原标题:Improve my Zend Stored Procedure calling code

我不禁要问,我如何能够改进我称之为储存程序的泽德法典。 此时,我使用的是MySQL DB,而我的控制者的行动功能却在发挥作用,但似乎已经nas。

public function callSPAction()
{
    $param = $this->_request->getParam( param , 0);

    $bootstrap = $this->getInvokeArg( bootstrap );
    $config = $bootstrap->getOptions();

    $mysqli = new mysqli(
        $config[ resources ][ db ][ params ][ host ],
        $config[ resources ][ db ][ params ][ root ][ username ],
        $config[ resources ][ db ][ params ][ root ][ password ],
        $config[ resources ][ db ][ params ][ dbname ]);

    $rs = $mysqli->query(sprintf( CALL mystoredprocedure(%d) ,$param));
    if(mysqli_error($mysqli))
    { 
        throw new exception(mysqli_error($mysqli), mysqli_errno($mysqli)); 
    } 
    $this->_helper->redirector( index ,  index );
}

我更喜欢使用Zentd_DB的班级,以说明所储存的程序,但并不确定如何做到这一点?

由于一把一些储存的程序称作零,因此,最好设立一个帮助小组,总结连接亚洲开发银行的逻辑。 它将暴露能够总结储存程序所依据的方法。 那么,我的控制员守则只能说话。

StoredProcedureHelper::callMyStoredProdecure($this->_request->getParam( param , 0);

这是可能的还是甚至建议的?

最佳回答

我赞成使用模型获取数据。 此外,我建议你在申请书中界定你的 d调器,使其与你的应用代码保持透明,并使用DO,因此,如果你今后需要指出一个不同的数据库,则你的申请并不与特定的亚洲开发银行管理人挂钩。

例如,在你的控制者的行动中,与其说是所有数据存取逻辑,而是可以简化如下:

//within some controller action
$model = MyUbberCoolSuperModel();
$model->myUbberCoolMethod($params);

//And in your model, which can extend Zend_Db_Table_Abstract
public function myUbberCoolMethod($params)
{
   $pdo = $this->getAdapter()->prepare("CALL myProcedure(:param)");
   $pdo->bindParam( :param , $param, PDO::PARAM_STR); 
   $pdo->execute();
   // Any additional logic you might want to do
}

我认为,这种方式更为清楚,你的控制者只负责采用模型方法,而模型则处理数据获取问题。 因此,如果与数据存取有关的任何事项都需要加以调整、修改或重,那么你知道,哪一种模式是你必须去做的,而不是改变任何可能影响任何其他情况的控制者行动。

希望会有助于;

乘客。

问题回答

暂无回答




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...

热门标签