Home > Article > Backend Development > A simple method to call ECMall's MySQL data_PHP tutorial
Many ecmall developers will ask how to use Ecmall's mysql class library to make data calls. In principle, the data call of Ecmall is based on the method of data module + module class library for mysql data call. All data modules are stored in the includesmodels directory. These calls are relatively complicated for beginners, such as product data. Calling functions cannot be used for data calls in stores. Each data table has its own function, its own class library and a small number of public class libraries. Therefore, for beginners, it is difficult to call mysql data.
Now we will explain a simple calling method that can satisfy more than 95% of mysql data calling requests. It is enough for secondary development of ecmall.
Example:
$db = &db(); // 第一步赋值数据库类库, $db->query(sql); // 第二步执行mysql 语句;
Commonly used database functions:
$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;
Detailed example:
function userlist() { $db = &db(); $user=$db->getall("select user_id from ecm_member "); foreach ( $user as $row) { echo "用户姓名=".$row['user_name']." 用户电话=".$row['tel']; } }