Ecmall MYSQL Database Call Tutorial

Source: Internet
Author: User

In principle, Ecmall data call is the Data module + module library to make MySQL data calls, all data modules are stored in the \includes\models directory, these calls for beginners is more complex, such as the product of the data call function, cannot be used in store data calls, each data table has its own class library of functions and a small number of public class libraries. Therefore, it is very difficult for beginners to call MySQL data.


I'm now going to explain a simple call method that satisfies more than 95% of MySQL data call requests. Enough to develop ecmall two times.

Examples are stored on a funding website.

Example:
$db = &db (); The first step is to assign the database class library,
$DB->query (SQL); The second step executes the MySQL statement;
Common database functions
1. Get a row of data
$user = $db->getrow ("select * from Ecm_member where user_id=111");
Print_r ($user);
2. Get a list of data
$user = $db->getcol ("Select user_id from Ecm_member");
Print_r ($user);
3. Get all the data
$user = $db->getall ("Select user_id from Ecm_member");
foreach ($user as $row)
{
Print_r ($row);
}
4. Get a value
$user = $db->getone ("SELECT count (*) from Ecm_member");
Echo $user;
5. Execute SQL statements
$db->query ("Update ecm_member set User_name= ' aaa '");
6. Get the last ID
$db->query ("Insert Ecm_member set user_name= ' aaa '");
$user _id = $db->insert_id ();
echo $user _id;


A detailed 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 '];
}

}

Ecmall MYSQL Database Call Tutorial

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.