Fetching data from MySQL db

F

Frank Moyles

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('$enc_user_name','$enc_password')");

if (mysqli_num_rows($result) != 0)
{
$data = $result->fetch_array(MYSQLI_BOTH);
return $data;
}
return null;
}



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

if (mysqli_num_rows($result) != 0)
{
$row = $result->fetch_array(MYSQLI_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#
 
N

Nicholas Paldino [.NET/C# MVP]

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).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top