有没有办法从c#应用程序连接到Magento数据库?

时间:2015-11-13 02:53:30

标签: c# magento

我想构建一个使用c#访问(读/写)magento数据库的应用程序。我想知道有没有办法从自定义应用程序连接?如果是,哪个会是最好的?请建议我,因为我是Magento的新手,谢谢。

2 个答案:

答案 0 :(得分:1)

我每天使用LINQPad(C#,VB.NET,F#)通过SSH隧道连接到我的Magento数据库。

有一个MySQL连接提供程序,它允许您使用Magento数据库有效地使用LINQ to SQL。

然后我可以直接从LINQPad运行查询,例如:

var items =
    from o in sales_flat_order
    where o.created_at > DateTime.Now.AddDays(-100)
    join i in sales_flat_order_item on o.entity_id equals i.order_id
    where i.sku.Contains(sku)
    join p in sales_flat_order_payment on o.entity_id equals p.parent_id
    orderby o.created_at descending
    select new
    {
        timestamp = o.created_at,
        order = o.increment_id,
        i.sku,
        i.name,
        qty = i.qty_ordered,
        o.status,
        p.method,
        i.row_total_incl_tax,
    };

然后,工具可以让您查看发送到数据库的实际查询。

SELECT t0.created_at, t0.increment_id, t1.sku, t1.name, t1.qty_ordered, t0.status, t2.method, t3.qty, t1.row_total_incl_tax
FROM sales_flat_order AS t0
INNER JOIN sales_flat_order_item AS t1
  ON (t0.entity_id = t1.order_id)
INNER JOIN sales_flat_order_payment AS t2
  ON (t0.entity_id = t2.parent_id)
INNER JOIN (
  SELECT t4.sku, t5.qty
  FROM catalog_product_entity AS t4
  INNER JOIN cataloginventory_stock_item AS t5
    ON (t4.entity_id = t5.product_id)
  WHERE (t4.sku LIKE CONCAT('%',@p0,'%'))
  ) AS t3
  ON (t1.sku = t3.sku)
WHERE ((t0.created_at > @p1) AND (t1.sku LIKE CONCAT('%',@p0,'%')))
ORDER BY t0.created_at DESC
-- p0 = [LEFCACP01]
-- p1 = [2015-08-07 16:13:31]

我也可以使用标准的.NET控件来执行图表等。

chart

我将它用于各种数据库报告和维护活动。

LINQPad

答案 1 :(得分:0)

您可以使用magento API执行此操作,下面的代码可能对您有帮助;

using Magento_Import.MagentoAPI;

namespace Magento_Import
{
    public partial class _Default : System.Web.UI.Page
    {
        Mage_Api_Model_Server_V2_HandlerPortTypeClient handler = new Mage_Api_Model_Server_V2_HandlerPortTypeClient();

        protected void Page_Load(object sender, EventArgs e)
        {
            string session = handler.login("username", "password");

            catalogProductEntity[] products;
            handler.catalogProductList(out products, session, null, null);
        }
    }
}