magento 在Magento中使用自己写的SQL语句
Magento的Models
和Collection
很强大,使用它们可以很方便的查询和操作数据库。但是有些场合,因为一些特殊需求或对Magento的了解不够深,可能会需要自己手写SQL语句来查询和操作数据库。以下分别是读写数据库的代码。
// For Read
// fetch read database connection that is used in Mage_Core module
$read= Mage::getSingleton('core/resource')->getConnection('core_read');
$value=$read->query("SE...");
$row = $value->fetch();
print_r($row); // As Array
// For Write
// fetch write database connection that is used in Mage_Core module
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
// now $write is an instance of Zend_Db_Adapter_Abstract
$write->query("insert into tablename values ('aaa','bbb','ccc')");
相关文档:
我在将Excel的数据导入到SQL的时候老是出现下面的错误:
配置选项 'show advanced options' 已从 1 更改为 1。请运行 RECONFIGURE 语句进行安装。
配置选项 'Ad Hoc Distributed Queries' 已从 1 更改为 1。请运行 RECONFIGURE 语句进行安装。
消息 7399,级别 16,状态 1,第 1 行
链接服务器 "(null)" 的 OLE DB 访问 ......
inner join(等值连接) 只返回两个表中联结字段相等的行
left join(左联接) 返回包括左表中的所有记录和右表中联结字段相等的记录
right join(右联接) 返回包括右表中的所有记录和左表中联结字段相等的记录
INNER JOIN 语法:
INNER JOIN 连接两个数据表的用法:
SELECT * from 表1 INNER JOIN 表2 ON 表1.字段号=表2 ......
这个逻辑关系乍看起来比较复杂,弄清楚了就好!
有两个表,
student(
id,
name,
primary key (id)
);
studentInfo(
id,
age,
address,
foreign key(id) references outTable(id) on delete cascade on update cascade
);
当我们删除student表的时候自然希望studentInfo里的相关信息也被删除,这就是外键起作用 ......
本文转自:http://industry.ccidnet.com/art/1106/20070514/1080519_1.html
本文是SQL Server SQL语句优化系列文章的第一篇。该系列文章描述了在Micosoft’s SQLServer2000关系数据库管理系统中优化SELECT语句的基本技巧,我们讨论的技巧可在Microsoft's SQL Enterprise Manager或 Microsoft SQL Query Anal ......