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条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 数学建模招标中位数问题
    • ¥15 phython路径名过长报错 不知道什么问题
    • ¥15 深度学习中模型转换该怎么实现
    • ¥15 HLs设计手写数字识别程序编译通不过
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向
    • ¥15 如何用python向钉钉机器人发送可以放大的图片?
    • ¥15 matlab(相关搜索:紧聚焦)
    • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计