dongweiben5229 2019-04-23 08:00
浏览 47

从PHP获取数据数组并将其传递给C#变量

I have a c# application that needs to send and retrieve using a PHP file. This PHP file then communicates with the database that the application uses for its data. My problem is, I don't know how to send and get array data between PHP and C#. Below is my code which only process one data, the student_id.

I tried finding tutorials and solution, and even API's but none could give the exact help I need.

Here is my PHP code:

class CaptureForm{
////LOCAL FUNCTION [->]
    private function query($sql, $arg, $fetch = false){
        require "config.php";
        $q = $db->prepare($sql);
        $q->execute($arg);
        return $fetch ? $q->fetch(2) : $q;
    }
private function getStud($stud_no){
        return $this->query("SELECT stud_id FROM tbl_students WHERE stud_id COLLATE latin1_bin LIKE ?", array($stud_no), true)["stud_id"];
    }

////LOCAL FUNCTION [<-]

     public function ShowStud($stud_no){
        if(empty($stud_no)) return "ERROR:MISSING_PARAMETERS";
        return $this->query("SELECT first_name FROM tbl_students WHERE stud_id  = ?", array($this->getStud($stud_no)), true)["first_name"];
    }
////USER FUNCTION [->]
    public function CheckWork($stud_no){ //=login
        if(empty($stud_no)) return "ERROR:MISSING_PARAMETERS";
        return  "OK:LOGGED_IN";
    }

and this is my C# code:

private void btn_in_Click(object sender, EventArgs e)
        {

            if (Execute("CheckWork", "stud_no=" + stud_num.Text) == 1)
            {
                stud_no = stud_num.Text; //To pass it to any other froms (=global)
                //same for pass
                WebClient fetchInfo = new WebClient();
                string studno = fetchInfo.DownloadString("http://localhost/server_api/clog.php?action=showStud&stud_no=" + stud_no);
                if (studno == "Michelle")
                {
                    MessageBox.Show("You are logged in! Yay!", "Logged in", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                else
                {
                    MessageBox.Show("You are logged in!", "Logged in", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }

            }
        }

Both codes are working very well but as I said, can only process one data. I expect to have an array of data to be sent to PHP then to the database and back from PHP to C# then output it as broken down strings. You can send the answer if you know or any other solution/tutorial that you can give. Thank you very much!!

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 对于相关问题的求解与代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作