ECMall的MySQL数据调用的简单方法
很多ecmall开发者会问,怎么使用Ecmall的mysql类库进行数据调用。从原理上来讲Ecmall的数据调用是以数据模块+模块类库的方式进行mysql数据调用的,所有数据模块都存储在includesmodels 目录下,这些调用对于初学者来讲是比较复杂的,例如商品的数据调用函数,不能用在店铺的数据调用上,每个数据表都有自己的函数自己的类库和少量的公共类库。因此初学者来讲,调用mysql数据很困难。
现在讲解一个简单的调用方法能满足95%以上的mysql数据调用请求。足够对ecmall进行二次开发。
例子:
$db = &db(); // 第一步赋值数据库类库, $db->query(sql); // 第二步执行mysql 语句;
Copy after login
常用的数据库函数:
- 得到一行数据
- 得到一列数据
- 得到所有数据
- 得到一个数值
- 执行sql语句
- 得到最后一个ID
$user=$db->getrow("select * from ecm_member where user_id=111"); print_r($user);
Copy after login
$user=$db->getcol("select user_id from ecm_member "); print_r($user);
Copy after login
$user=$db->getall("select user_id from ecm_member "); foreach ( $user as $row) { print_r($row); }
Copy after login
$user=$db->getone("select count(*) from ecm_member "); echo $user;
Copy after login
$db->query("update ecm_member set user_name='aaa' ");
Copy after login
$db->query("insert ecm_member set user_name='aaa' "); $user_id = $db->insert_id(); echo $user_id;
Copy after login
详细的例子:
function userlist() { $db = &db(); $user=$db->getall("select user_id from ecm_member "); foreach ( $user as $row) { echo "用户姓名=".$row['user_name']." 用户电话=".$row['tel']; } }
Copy after login
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article
Roblox: Grow A Garden - Complete Mutation Guide
3 weeks ago
By DDD
Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
How to fix KB5055612 fails to install in Windows 10?
3 weeks ago
By DDD
Nordhold: Fusion System, Explained
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago
By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics
Java Tutorial
1665
14


CakePHP Tutorial
1424
52


Laravel Tutorial
1322
25


PHP Tutorial
1270
29


C# Tutorial
1249
24

