Skip to content

Instantly share code, notes, and snippets.

@ctaggart
Created December 13, 2015 01:15
Show Gist options
  • Save ctaggart/1e5606e9d6c52c5317e3 to your computer and use it in GitHub Desktop.
Save ctaggart/1e5606e9d6c52c5317e3 to your computer and use it in GitHub Desktop.
MySQL F# Guestbook getting started
// nuget MySql.Data
// requires System.Configuration, System.Data, System.Transactions
open MySql.Data.MySqlClient
[<EntryPoint>]
let main argv =
use conn = new MySqlConnection("server=104.154.70.124;database=guestbook;uid=root")
conn.Open()
use cmd = new MySqlCommand("select * from entries", conn)
// cmd.Prepare()
use r = cmd.ExecuteReader()
while r.Read() do
let id = r.GetInt32 0
let guestName = r.GetString 1
let content = r.GetString 2
printfn "id: %d, guestName: %s, content: %s" id guestName content
0
CREATE DATABASE guestbook;
CREATE TABLE guestbook.entries (
entryID INT NOT NULL AUTO_INCREMENT,
guestName VARCHAR(255),
content VARCHAR(255),
PRIMARY KEY(entryID)
);
INSERT INTO `guestbook`.`entries` (`guestName`, `content`) VALUES ('Cameron', 'This is my first MySQL in a long time!');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment