-** Testing for Mono's MySQL provider (Mono.Data.MySql)
-
-<ul>
- <li>Have access to a MySQL database or download it from
- <ul>
- <li><a href="http://www.mysql.com/downloads/index.html">MySQL AB</a></li>
- </ul>
- </li>
-
- <li>Take a look at MySqlTest.cs in mcs/class/Mono.Data.MySql/Test</li>
- <li>On Linux, you may need to make a symbolic link from libmySQL.dll to libmysqlclient.dll</li>
-
- <li>Has a ConnectionString format:
-<pre>
- "Server=hostname;Database=database;User ID=username;Password=password"
- (or)
- "Host=hostname;Dbname=database;User=username;Passwd=password"
-</pre>
-
- <li>C# Example:
-<pre>
- using System;
- using System.Data;
- using Mono.Data.MySql;
-
- public class Test
- {
- public static void Main(string[] args)
- {
- string connectionString =
- "Server=localhost;" +
- "Database=test;" +
- "User ID=myuserid;" +
- "Password=mypassword;";
- IDbConnection dbcon;
- dbcon = new MySqlConnection(connectionString);
- dbcon.Open();
- IDbCommand dbcmd = dbcon.CreateCommand();
- // requires a table to be created named employee
- // with columns firstname and lastname
- // such as,
- // CREATE TABLE employee (
- // firstname varchar(32),
- // lastname varchar(32));
- string sql =
- "SELECT firstname, lastname " +
- "FROM employee";
- dbcmd.CommandText = sql;
- IDataReader reader = dbcmd.ExecuteReader();
- while(reader.Read()) {
- string FirstName = reader["firstname"];
- string LastName = reader["lastname"];
- Console.WriteLine("Name: " +
- FirstName + " " + LastName);
- }
- // clean up
- reader.Close();
- reader = null;
- dbcmd.Dispose();
- dbcmd = null;
- dbcon.Close();
- dbcon = null;
- }
- }
-</pre>
- </li>
- <li>Building C# Example:
- <ul>
- <li>Save the example to a file, such as, TestExample.cs</li>
- <li>Build on Linux:
-<pre>
- mcs TestExample.cs \
- -r System.Data.dll \
- -r Mono.Data.MySql.dll
-</pre>
- </li>
- <li>Build on Windows via Cygwin:
-<pre>
- mono C:/cygwin/home/MyHome/mono/install/bin/mcs.exe \
- TestExample.cs \
- -lib:C:/cygwin/home/MyHome/mono/install/lib \
- -r System.Data.dll \
- -r Mono.Data.MySql.dll
-</pre>
- </li>
- </ul>
- </li>
- <li>Running the Example:
-<pre>
-mono TestExample.exe
-</pre>
- </li>
-
-</ul>