将 C# 格式转换为 PHP

编程


这个预成型件对于程序员来说非常有帮助。 社区非常有帮助。
我一般用c#语言编写程序,但对php不太了解。
在一个项目中,我需要用 PHP 编写一些代码。
请帮我…
这个例子将帮助我学习php

网络平台
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;       
    }

我尝试过的:

抱歉,我不知道如何更改此代码

解决方案1

我们不是“C# 到 PHP”的翻译者。

我建议阅读以下内容: 如何开始? | C# 到 PHP 转换器[^]

コメント

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