ECMall's simple method for calling MySQL data _ PHP Tutorial

Source: Internet
Author: User
ECMall is a simple method for calling MySQL data. Many ecmall developers will ask how to use the mysql class library of Ecmall to call data. In principle, Ecmall data calling is performed by using the data module + Module class library for mysql data calling. many ecmall developers will ask how to use the Ecmall mysql class library for data calling. In principle, Ecmall calls mysql data in the form of a data module + Module class library. all data modules are stored in the includesmodels directory, these calls are complex for beginners. for example, the product data call function cannot be used for store data calls, each data table has its own function class library and a small number of public class libraries. Therefore, it is difficult for beginners to call mysql data.

A simple call method can meet more than 95% of mysql data call requests. Sufficient for secondary development of ecmall.

Example:

$ Db = & db (); // value the database class library in step 1, $ db-> query (SQL); // execute the mysql statement in step 2;

Common Database functions:

  1. Get a row of data
  2. $user=$db->getrow("select * from ecm_member where user_id=111");print_r($user);
  3. Get a column of data
  4. $user=$db->getcol("select user_id from ecm_member ");print_r($user);
  5. Get all data
  6. $user=$db->getall("select user_id from ecm_member ");foreach ( $user as $row){print_r($row);}
  7. Returns a value.
  8. $user=$db->getone("select count(*) from ecm_member ");echo $user;
  9. Execute SQL statements
  10. $db->query("update ecm_member  set user_name='aaa' ");
  11. Obtain the last ID.
  12. $db->query("insert ecm_member  set user_name='aaa' ");$user_id = $db->insert_id();echo $user_id;

Example:

Function userlist () {$ db = & db (); $ user = $ db-> getall ("select user_id from ecm_member"); foreach ($ user as $ row) {echo "user name = ". $ row ['User _ name']. "User phone = ". $ row ['tel'];}

Bytes. In principle, Ecmall's data calling is based on the data module + Module class library for mysql data calling...

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.