如何使用准备好的语句制作合适的mysqli扩展类?

如何使用准备好的语句制作合适的mysqli扩展类?,第1张

如何使用准备好的语句制作合适的mysqli扩展类?

检查Zend_Db的实现,尤其是

Zend_Db_Select
。实际上,您可能只是选择使用它而不是自己开发。例子

 //connect to a database using the mysqli adapter //for list of other supported adapters see //http://framework.zend.com/manual/en/zend.db.html#zend.db.adapter.adapter-notes$parameters = array(         'host'     => 'xx.xxx.xxx.xxx',         'username' => 'test',         'password' => 'test',         'dbname'   => 'test'        );try {    $db = Zend_Db::factory('mysqli', $parameters);    $db->getConnection();} catch (Zend_Db_Adapter_Exception $e) {    echo $e->getMessage();    die('Could not connect to database.');} catch (Zend_Exception $e) {    echo $e->getMessage();    die('Could not connect to database.');}//a prepared statement$sql = 'SELECT * FROM blah WHERe id = ?';$result = $db->fetchAll($sql, 2);//example using Zend_Db_Select$select = $db->select()  ->from('blah')  ->where('id = ?',5);print_r($select->__toString());$result = $db->fetchAll($select);//inserting a record$row = array('name' => 'foo',  'created' => time() );$db->insert('blah',$row);$lastInsertId = $db->lastInsertId();//updating a row$data = array(    'name'      => 'bar',    'updated'   => time());$rowsAffected = $db->update('blah', $data, 'id = 2');


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5675654.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存