将PHP转换为C# [英] Converting PHP to C#

查看:60
本文介绍了将PHP转换为C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将以下代码从PHP转换为C#并需要帮助



I want to convert the code below from PHP to C# and need help

<!--?php function getUserHints($attr,$value)
 {    
 // configurations     
  $tableUsers = 'users';    
   $tableCols = array('id'=-->'id',
        'name'=>'name',
        'email'=>'name',
        'display'=>'display'
    );
 
    // get parameters:
    //   search table $tableUsers by column defined in $tableCols
    // if search column not found, return empty array
    if (isset($tableCols[$attr])) {
        $col = $tableCols[$attr];
        $value = mysql_real_escape_string($value);
    } else {
        return array();
    }
 
    $sql = "SELECT * FROM `$tableUsers` WHERE `$col` LIKE '$value%'";
    $res = mysql_query($sql);
 
    if (!$res) {
        return array();
    }
 
    $ret = array();
    while ($tmp = mysql_fetch_assoc($res)) {
        $ret[] = array(
            'id'=>$tmp[$tableCols['id']],
            'name'=>$tmp[$tableCols['name']],
            'email'=>$tmp[$tableCols['email']],
            'display'=>$tmp[$tableCols['display']],
            'label'=>$tmp[$tableCols['display']]."(".$tmp[$tableCols[$attr]].")",
            'value'=>$tmp[$tableCols[$attr]]
        );
    }
 
    return $ret;
}
 
if (isset($_POST['attr'])) {
    mysql_connect('localhost','dbuser','dbpass');
    mysql_select_db('dbname');
    mysql_query("SET NAMES utf8");
    $ret = getUserHints($_POST['attr'],$_POST['value']);
    echo json_encode($ret);
}

推荐答案

attr,


value)
{
// 配置
value) { // configurations


tableUsers = ' users';
tableUsers = 'users';


这篇关于将PHP转换为C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆