Created
December 13, 2015 01:15
-
-
Save ctaggart/1e5606e9d6c52c5317e3 to your computer and use it in GitHub Desktop.
MySQL F# Guestbook getting started
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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