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