Chuyển đổi dạng C# sang PHP

lập trình


Biểu mẫu này rất hữu ích cho các lập trình viên. Cộng đồng rất hữu ích.
Tôi thường viết chương trình bằng ngôn ngữ c#, nhưng tôi không biết php ở trình độ nâng cao.
Trong một dự án, tôi cần viết một số mã bằng PHP.
làm ơn giúp tôi…
Ví dụ này sẽ giúp tôi học php

ASP.NET
protected void Page_Load(object sender, EventArgs e)
    {

    }
    [System.Web.Services.WebMethod()]
    public static string getServerTime()
    {
        DateTime dt = DateTime.Now;
        return "Server_Time: " + dt.ToString();
    }
    [System.Web.Services.WebMethod]
    public static string get_mobinfo(string mobileno, string deviceid)
    {
        string tData;
        string remark_dl = ""; ;
        connect.connect_class cnn = new connect.connect_class();
        System.Data.DataTable dt = new System.Data.DataTable();
       
        string getsql = "SELECT free_join.Associate_Name, free_join.Mobile_No FROM free_join WHERE free_join.Mobile_No =  '" + mobileno + "'";
        dt = cnn.selctqrydtbl(getsql);

        // convert datatable to json using 
        tData = cnn.DataTable_2_JSON(dt);
        if (tData.Length > 2)
        {
            remark_dl = "Geting mobileinfo :" + mobileno + " :" + tData;
        }
        else
        {
            remark_dl = "Geting mobileinfo :" + mobileno + ":Not found";
        }

        
        string strSessionID = HttpContext.Current.Session.SessionID;
        string current_trackingid = cnn.create_trackingid(strSessionID);

       
        return tData;
    }

    [System.Web.Services.WebMethod]
    public static string get_shopdata(string mobile, string category)
    {
        string tData;
        string getsql;
        connect.connect_class cnn = new connect.connect_class();
        System.Data.DataTable dt = new System.Data.DataTable();
        if (category == "cat_toy")
        {
            getsql = "SELECT shop_product.slno AS SL_No, shop_product.productid AS Product_ID, shop_product.productname AS Product_Name, shop_product.price_mrp AS MRP, shop_product.price_offer AS Our_Price, shop_product.cat AS Category, shop_product.`status` AS Status FROM shop_product  WHERE status ='Active'";
            
        }
        else
        {
            getsql = "SELECT * from shop_product";
        }

        dt = cnn.selctqrydtbl(getsql);
        tData = cnn.DataTable_2_JSON(dt);

        Newtonsoft.Json.Linq.JObject product_obj = new Newtonsoft.Json.Linq.JObject();
        product_obj["ProductArray"] = tData;

        string product_json = product_obj.ToString();
       
        string getsql_cat = "SELECT * FROM shop_tag WHERE shop_tag.`status` = 'Active'";

        dt = null;
        dt = cnn.selctqrydtbl(getsql_cat);
        string tData_cat = cnn.DataTable_2_JSON(dt);

        Newtonsoft.Json.Linq.JObject cat_obj = new Newtonsoft.Json.Linq.JObject();
        cat_obj["CatArray"] = tData_cat;

        string cat_json = cat_obj.ToString();

        product_obj.Merge(cat_obj);

        string getsql_wish = "SELECT * FROM wishlist WHERE wishlist.`status` =  'A' AND wishlist.usermobile = '" + mobile + "' ORDER BY wishlist.slno ASC";

        dt = null;
        dt = cnn.selctqrydtbl(getsql_wish);
        string tData_wishlist = cnn.DataTable_2_JSON(dt);

        Newtonsoft.Json.Linq.JObject wish_obj = new Newtonsoft.Json.Linq.JObject();
        wish_obj["WishArray"] = tData_wishlist;

        product_obj.Merge(wish_obj);

        string retrnjson = product_obj.ToString();
        return retrnjson;
    }
    [System.Web.Services.WebMethod]
    public static string save_wishlist(string mobile, string fpid)
    {
        string tData;
        string getsql;
        connect.connect_class cnn = new connect.connect_class();
        System.Data.DataTable dt = new System.Data.DataTable();

        string jdat = null;
        string dtformat = "dd-MM-yyyy HH:mm:ss";

        DateTime dtime = cnn.localtime();
        jdat = dtime.ToString(dtformat);

        string insrtlogin = "insert into wishlist(usermobile,productid,doj,status) values('" + mobile + "','" + fpid + "','" + jdat + "','A')";
        cnn.selctqrydtbl(insrtlogin);       

        return "datasave";
    }
    public int GET_MAX_ID(string tbl_name, string fld_name)
    {
        int MAX_slno = 0;
        MySql.Data.MySqlClient.MySqlConnection mycn = new MySql.Data.MySqlClient.MySqlConnection();
        connect.connect_class cnn = new connect.connect_class();
        if (mycn.State == System.Data.ConnectionState.Open)
        {
            mycn.Dispose();
            mycn.Close();
        }
        mycn = cnn.myconect();

        string sql = "select max(" + fld_name + ") from " + tbl_name + "";
        MySql.Data.MySqlClient.MySqlDataAdapter cmd1 = new MySql.Data.MySqlClient.MySqlDataAdapter(sql, mycn);

        System.Data.DataTable dt = new System.Data.DataTable();
        cmd1.Fill(dt);
        if (dt.Rows.Count > 0)
        {
            string tmxid = dt.Rows[0][0].ToString();
            if (tmxid == "")
            {
                MAX_slno = 1;

            }
            else
            {
                MAX_slno = int.Parse(tmxid) + 1;
            }
        }
        return MAX_slno;       
    }

Những gì tôi đã thử:

xin lỗi tôi không biết cách thay đổi mã này

Giải pháp 1

Chúng tôi không phải là người dịch “C# sang PHP”.

Tôi khuyên bạn nên đọc cái này: Làm thế nào để bắt đầu? | Trình chuyển đổi C# sang PHP[^]

コメント

タイトルとURLをコピーしました