Home  >  Article  >  Backend Development  >  A simple method to call ECMall's MySQL data_PHP tutorial

A simple method to call ECMall's MySQL data_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 10:33:54924browse

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:

  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. Get a value
  8. $user=$db->getone("select count(*) from ecm_member ");
    echo $user;
    
  9. Execute sql statement
  10. $db->query("update ecm_member  set user_name='aaa' ");
    
  11. Get the last ID
  12. $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'];
	}
}

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/752377.htmlTechArticleMany ecmall developers will ask how to use Ecmall's mysql class library to make data calls. In principle, Ecmall's data call is based on data module + module class library for mysql data call...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn