Ecmall MySql 資料庫調用教程

來源:互聯網
上載者:User

標籤:

從原理上來講Ecmall的資料調用是以資料模組+模組類庫的方式進行mysql資料調用的,所有資料模組都儲存在\includes\models 目錄下,這些調用對於初學者來講是比較複雜的,例如商品的資料調用函數,不能用在店鋪的資料調用上,每個資料表都有自己的函數自己的類庫和少量的公用類庫。因此初學者來講,調用mysql資料很困難。


我現在講解一個簡單的調用方法能滿足95%以上的mysql資料調用請求。足夠對ecmall進行二次開發。

例子儲存在配資網站上。

例子:
$db = &db(); 第一步賦值資料庫類庫,
$db->query(sql); 第二步執行mysql 語句;
常用的資料庫函數
1.得到一行資料
$user=$db->getrow("select * from ecm_member where user_id=111");
print_r($user);
2.得到一列資料
$user=$db->getcol("select user_id from ecm_member ");
print_r($user);
3.得到所有資料
$user=$db->getall("select user_id from ecm_member ");
foreach ( $user as $row)
{
print_r($row);
}
4.得到一個數值
$user=$db->getone("select count(*) from ecm_member ");
echo $user;
5.執行sql語句
$db->query("update ecm_member  set user_name=‘aaa‘ ");
6.得到最後一個ID
$db->query("insert ecm_member  set user_name=‘aaa‘ ");
$user_id = $db->insert_id();
echo $user_id;


詳細的例子
function userlist()
{
$db = &db();
$user=$db->getall("select user_id from ecm_member ");
foreach ( $user as $row)
{
echo "使用者姓名=".$row[‘user_name‘]." 使用者電話=".$row[‘tel‘];
}

}

Ecmall MySql 資料庫調用教程

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.