很多ecmall开发者会问,怎么使用Ecmall的mysql类库进行数据调用。从原理上来讲Ecmall的数据调用是以数据模块+模块类库的方式进行mysql数据调用的,所有数据模块都存储在includesmodels 目录下,这些调用对于初学者来讲是比较复杂的,例如商品的数据调用函数,不能用在店铺的数据调用上,每个数据表都有自己的函数自己的类库和少量的公共类库。因此初学者来讲,调用mysql数据很困难。
现在讲解一个简单的调用方法能满足95%以上的mysql数据调用请求。足够对ecmall进行二次开发。
例子:
$db = &db(); // 第一步赋值数据库类库, $db->query(sql); // 第二步执行mysql 语句;
常用的数据库函数:
- 得到一行数据
- 得到一列数据
- 得到所有数据
- 得到一个数值
- 执行sql语句
- 得到最后一个ID
$user=$db->getrow("select * from ecm_member where user_id=111"); print_r($user);
$user=$db->getcol("select user_id from ecm_member "); print_r($user);
$user=$db->getall("select user_id from ecm_member "); foreach ( $user as $row) { print_r($row); }
$user=$db->getone("select count(*) from ecm_member "); echo $user;
$db->query("update ecm_member set user_name='aaa' ");
$db->query("insert ecm_member set user_name='aaa' "); $user_id = $db->insert_id(); echo $user_id;
详细的例子:
function userlist() { $db = &db(); $user=$db->getall("select user_id from ecm_member "); foreach ( $user as $row) { echo "用户姓名=".$row['user_name']." 用户电话=".$row['tel']; } }

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

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Zend Studio 13.0.1
Powerful PHP integrated development environment

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),
