Magento 通过SQL语句查找插入数据
来源:互联网 发布:ubuntu挂载硬盘到data 编辑:程序博客网 时间:2024/05/01 01:19
想要直接查找magento的数据先要调用magento的resource方法:
$read = Mage::getSingleton('core/resource')->getConnection('core_read');$sql = "select name from user_data where id = 1 limit 1"; //$row = $read->fetchAll($sql ); //查找出所有的数据记录
上面是直接通过SQL语句查找数据内容,下面是通过magento自带的数据库查找:
$read = Mage::getSingleton('core/resource')->getConnection('core_read');$table = Mage::getSingleton('core/resource')->getTableName('dipper_tdata/table');//根据config.xml里面的设置获取表名。$select = $read->select()->from($table)->where("sup_id = 10000 and postage_type = 0");$row = $read->fetchAll($select); //查找出所有的数据记录
这样就可以查询到你想要的任何数据了。
Magento数据插入:
$write = Mage::getSingleton('core/resource')->getConnection('core_write');//调用resource的write方法$sql = "insert into user_data values(?,?)";//INSERT INTO table_name (列1, 列2,...) VALUES (值1, 值2,....)$write->query($sql,array('name','pass'));
上面是直接用SQL语句,下面是用magento自带的方法:
$write = Mage::getSingleton('core/resource')->getConnection('core_write');$table = Mage::getSingleton('core/resource')->getTableName('dipper_tdata/table');$insertdata = array('name'=>'test','sex'=>'男');$write->insert($table, $insertdata);//这样就可以把数组里面的数据插入到数据表里面了$write->commit();//数据插入
这样能查询能插入。Magento的数据库操作就更加简便了。更利于开发
- Magento 通过SQL语句查找插入数据
- 通过SQL语句手动向DISCUZ x2 插入帖子数据
- SQL 语句 insert 插入数据
- SQL语句批量插入数据
- ORACLE 通过spid查找sql语句
- Oracle通过Select语句来插入数据
- magento 输出sql语句
- 批量数据插入的SQL语句
- Sql语句学习笔记(3)-插入数据
- 一条SQL语句 插入多条数据
- sql语句插入数据(Identity修饰)
- 大批量插入数据时优化SQL语句
- 处理数据批量生成sql插入语句
- Mysql批量插入数据sql语句
- 批量插入数据的SQL语句
- T-sql语句批量插入数据
- MS CRM2011 通过sql插入数据
- sql语句查找记录中的连续数据
- 详述JavaScript的内置对象
- PROPSHEETPAGE Structure
- 七夕,情无处投递
- edm邮件制作须知
- Android 的用户层 uevent处理机制
- Magento 通过SQL语句查找插入数据
- VS2008的路径宏TargetPath
- linux下 USB动态监测 hotplug事件监测
- lamp
- Js操作Select大全
- 中断上下文、进程上下文
- UpdatePanel的用法详解
- SVN使用简介
- 一个局外SEO人看360搜索