Fetching data from MySQL db

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Frank Moyles

    #1

    Fetching data from MySQL db

    I have two simple function in PHP that I want to convert to C# -

    function Doit($enc_user_ name, $enc_password)
    {
    $result = $mysqli->query("call
    sp_userAuth('$e nc_user_name',' $enc_password') ");

    if (mysqli_num_row s($result) != 0)
    {
    $data = $result->fetch_array(MY SQLI_BOTH);
    return $data;
    }
    return null;
    }



    function JustDoit($user_ id, $session_id)
    {
    $result = $mysqli->query("call
    sp_userMultiLog in('$user_id', $seesion_id)");

    if (mysqli_num_row s($result) != 0)
    {
    $row = $result->fetch_array(MY SQLI_BOTH);
    return $row['session_id'];
    }
    return null ;
    }


    Can anyone show me how I may port them to C#?. I am using the OleDbData
    Provider to access the MySQL database. The examples you provide are
    really to help me no how to :

    1). Pass parameters to a stored procedure (in the PHP code above, all
    parameters are strings - apart from user_id, which maps to a C# uint)

    2). Return a dataset back to C#

    3). Return the value for a specific column back to C#
  • Nicholas Paldino [.NET/C# MVP]

    #2
    Re: Fetching data from MySQL db

    Frank,

    Well, if you are using the OleDb providers for .NET, then you would do
    these things the way that you would for any other data access. This
    involves defining your parameterized command, adding/populating the
    parameters on your command, executing a reader on it (or, assigning it to a
    data adapter if you want to fill a dataset).

    You also might want to look at the .NET connector for MySql:

    http://dev.mysql.com/downloads/connector/net/5.1.html

    As it follows the pattern for data access in .NET (and is probably more
    efficient, in that is accessing the source natively, as opposed to going
    through an indirection layer like OleDb).


    --
    - Nicholas Paldino [.NET/C# MVP]
    - mvp@spam.guard. caspershouse.co m

    "Frank Moyles" <fgmoyles@nospa m.comwrote in message
    news:3q6dnU_yk5 qVQenanZ2dnUVZ8 qminZ2d@bt.com. ..
    >I have two simple function in PHP that I want to convert to C# -
    >
    function Doit($enc_user_ name, $enc_password)
    {
    $result = $mysqli->query("call
    sp_userAuth('$e nc_user_name',' $enc_password') ");
    >
    if (mysqli_num_row s($result) != 0)
    {
    $data = $result->fetch_array(MY SQLI_BOTH);
    return $data;
    } return null;
    }
    >
    >
    >
    function JustDoit($user_ id, $session_id)
    {
    $result = $mysqli->query("call sp_userMultiLog in('$user_id',
    $seesion_id)");
    if (mysqli_num_row s($result) != 0)
    {
    $row = $result->fetch_array(MY SQLI_BOTH);
    return $row['session_id'];
    } return null ; }
    >
    >
    Can anyone show me how I may port them to C#?. I am using the OleDbData
    Provider to access the MySQL database. The examples you provide are really
    to help me no how to :
    >
    1). Pass parameters to a stored procedure (in the PHP code above, all
    parameters are strings - apart from user_id, which maps to a C# uint)
    >
    2). Return a dataset back to C#
    >
    3). Return the value for a specific column back to C#

    Comment

    Working...