Magento 中执行SQL语句.[magento二次开发]
来源:互联网 发布:java 表格 编辑:程序博客网 时间:2024/05/16 18:50
在做开发时有的时候迷惑,Magento都提供了数据的对象,那该如何查询自定义的SQL语句呢.
其实Magento已经想过这个问题了.
只需instance core/resource的对象进行connect就能得到数据访问的对象了.语法是跟Zend_Db一致的.
看代码:
- <?php
- //select query
- $read = Mage::getSingleton('core/resource')->getConnection('core_read');
- //make connection
- $qry = "select name FROM user_data WHERE id=1 LIMIT 1 "; //query
- $res = $read->fetchRow($qry); //fetch row
- $name = $res['name']; //outputs name
- //other form
- $qry = "select name FROM user_data WHERE namer LIKE '%a%' ";//query
- $res = $read->fetchAll($qry); //get array
- //Insert query
- $write = Mage::getSingleton('core/resource')->getConnection('core_write');
- $sql = "INSERT INTO user_data values (?,?)"; //insert query
- $write->query($sql, array('name','pass')); //write to database
- ?>
像fetch fetchall这样的方法是不是以前经常用到,没错.Zend_Db同样和PDO的风格差不多.
0 0
- Magento 中执行SQL语句.[magento二次开发]
- Magento 中执行SQL语句.
- magento 中查看执行的sql语句
- magento -- 在Magento中获取SQL语句
- magento -- 在Magento中使用自己写的SQL语句
- magento 执行sql
- Magento中如何调用SQL语句
- Magento中打印SQL语句来调试
- Magento中直接使用SQL语句
- 在Magento中直接使用SQL语句
- Magento中直接使用SQL语句
- magento中打印运行的SQL语句
- magento 中 直接写sql语句
- Magento中打印SQL语句来调试
- magento 输出sql语句
- 在magento layout中加入外部js 【magento二次开发】
- Magento模块中添加计划任务Cron Job【magento二次开发】
- Magento输出查询SQL语句
- Git 命令参数及用法详解
- ActiveX控件与Javascript之间的交互
- java中的这几个问题你是否知道
- DP复习
- 前台验证
- Magento 中执行SQL语句.[magento二次开发]
- 【LeetCode】Merge Two Sorted Lists
- ios framework通用库的制作
- [算法入门经典] 例题7-3 倒水问题 | HDU 1495
- .bash_profile和.bashrc的区别(如何设置生效)
- Swift简介
- 微软编程之美2014挑战赛之题目2 : 大神与三位小伙伴 题解
- html中的get和post的区别
- Excel创建按钮调用宏