Archive for January, 2007

MySQL & C#

Recently, i’ve been coding some stuff that interacts with mysql from C#, and its taken me quite a long time to get some basic stuff working. Here is a basic tutorial to get the stuff working basicly (ie; connecting to database, reading results from rows.).

 

Ok, first get MySQL Connector .NET.  Add it as a reference via Visual Studio, and add “using MySql.Data.MySqlClient;” to the top of your application.

Now, to get to the bones of it.  The basic connect strings i have been using are:

 

   1:  conDatabase = new MySqlConnection(“server=brentp.net; user id=bah; password=bahblacksheep; database=haveyouany; pooling=false;”);

 

 That connects us to the database.

 

MySqlConnection conDatabase = new MySqlConnection(“server=faklas.net; user id=wha; password=asf; database=asfasfa; pooling=false;”);
string Query = “SELECT * FROM `blah`”;
conDatabase.Open();
MySqlCommand cmd = new MySqlCommand(Query, conDatabase);
MySqlDataReader read = cmd.ExecuteReader();
while (read.Read())
   {
   if (read[0].ToString() == “whatever”)
        // do something
         }
    }
read.Close();
conDatabase.Close();

Thats all the  code there that allows us to connect to the database, read a result and do something depending on what it says.  read[0] is the first result from the dataset, (if its easier to you, you can use the name of the column, rather than the index of the row).  This can be made more efficent if you use it multiple times.  If you wish to execute a command where you wish to get no feedback (insert, update, delete), you just use:

 

string strDelete = “INSERT DELETE OR UPDATE COMMAND HERE.”;
// CONNECT HERE.
MySqlCommand cmdDatabase = new MySqlCommand(strDelete, conDatabase);
conDatabase.Open();
    try
    {
    cmdDatabase.ExecuteNonQuery();
    }
    catch (MySqlException mye)
    {
    MessageBox.Show(mye.ToString(), “Error:”, MessageBoxButtons.OK, MessageBoxIcon.Error);
    }
conDatabase.Close();
 

Note: You can use ‘int bleh = cmdDatabase.ExecuteNonQuery();’ then ‘rowsc.ToString()’ for the number of rows changed with the query to see if it worked or not.  Of course, you could do better error handling than what i included here (ie; checking if you actually connected to the db, because if you didnt, the application would throw an exception and crash.  Easy way to fix this would to try, catch and finally.  Thats all i have for tonight, gotta find something to do before alias starts at 12:30 (assuming the tennis doesnt run  over again.  Goddamn channel 7 and their sports coverage).  Enjoy.

 

PS: check out violentacres.com.

3.03 OE-A Released.

Early this morning 3.03 OE-A was released.  The link to the file is: http://brentp.net/303oe.rar.  This release has some advantages over OE-B (one of which is PSX game compression, so all those ps1 games dont take a huge chunk outta your memory stick).  There were other various bugfixes included, and the release of an SDK for 3.03 is great news for the psp homebrew community.  To apply the update, its the same as any other OE release, download the 1.50 update, download the 3.03 update, download the oe-a file (above) and generate the DATA.DXAR.  Then copy the dxar to /PSP/GAME150/303updateflasher (or whatever it is) and wait a few minutes.  As always, read the readme before you try anything here.  This program writes to your flash, so there is always the chance of bricking. Enjoy.

Apache Conf

For those who are running an Apache server, ive found the following bare-bones configuration.  It just serves files and indexes directories.  This is assuming that you’ve compiled apache with shared libraries.

 

   1:  Listen 80
   2:  ServerRoot /usr/local/apache20
   3:  DocumentRoot /usr/local/apache20/htdocs
   4:  LoadModule autoindex_module modules/mod_autoindex.so
   5:  LoadModule dir_module modules/mod_dir.so
   6:  LoadModule access_module modules/mod_access.so
   7:   
   8:  User  nobody
   9:  # If you’re not on Linux, you’ll probably need to change Group
  10:  Group nobody
  11:   
  12:  <IfModule prefork.c>
  13:  MaxClients       150
  14:  StartServers     5
  15:  MinSpareServers  5
  16:  MaxSpareServers 10
  17:  </IfModule>
  18:   
  19:  <IfModule worker.c>
  20:  StartServers         2
  21:  MaxClients         150
  22:  MinSpareThreads     25
  23:  MaxSpareThreads     75
  24:  ThreadsPerChild     25
  25:  MaxRequestsPerChild  0
  26:  </IfModule>
  27:   
  28:  # Assume no memory leaks at all
  29:  MaxRequestsPerChild 0
  30:   
  31:  # it’s always nice to know the server has started
  32:  ErrorLog logs/error_log
  33:   
  34:  # Some benchmarks require logging, which is a good requirement.  Uncomment
  35:  # this if you need logging.
  36:  #TransferLog logs/access_log
  37:   
  38:  <Directory />
  39:      # The server can be made to avoid following symbolic links,
  40:      # to make security simpler. However, this takes extra CPU time,
  41:      # so we will just let it follow symlinks.
  42:      Options Indexes FollowSymLinks
  43:   
  44:      # Don’t check for .htaccess files in each directory - they slow
  45:      # things down
  46:      AllowOverride None
  47:   
  48:      # If this was a real internet server you’d probably want to
  49:      # uncomment these:
  50:      order allow,deny
  51:      allow from all
  52:  </Directory>
  53:   
  54:  # If this was a real internet server you’d probably want to uncomment this:
  55:  <Directory “/usr/local/apache20/htdocs”>
  56:      order allow,deny
  57:      allow from all
  58:      Options Indexes FollowSymLinks
  59:      #Options All
  60:  </Directory>