Many Ecmall developers will ask how to make data calls using the Ecmall MySQL class library. In principle, Ecmall data call is the Data module + module library to make MySQL data calls, all data modules are stored in the Includesmodels 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.
Now, a simple call method can satisfy more than 95% of MySQL data call requests. Enough to develop ecmall two times.
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:
- Get a row of data
$user = $db->getrow ("select * from Ecm_member where user_id=111");p Rint_r ($user);
- Get a list of data
$user = $db->getcol ("Select user_id from Ecm_member");p Rint_r ($user);
- Get all the data
$user = $db->getall ("Select user_id from Ecm_member"), foreach ($user as $row) {print_r ($row);}
- Get a value
$user = $db->getone ("SELECT count (*) from Ecm_member"); Echo $user;
- Execute SQL statement
$db->query ("Update ecm_member set user_name= ' aaa '");
- 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 '];}}
http://www.bkjia.com/PHPjc/752377.html www.bkjia.com true http://www.bkjia.com/PHPjc/752377.html techarticle Many Ecmall developers will ask how to make data calls using the Ecmall MySQL class library. In principle, Ecmall data call is the Data module + Module Library of the way to do MySQL data transfer ...