Skip to content

Instantly share code, notes, and snippets.

@DanielAugusto191
Created August 21, 2024 20:24
Show Gist options
  • Select an option

  • Save DanielAugusto191/87bf42d0f9d1d9ef5cec4225b0700469 to your computer and use it in GitHub Desktop.

Select an option

Save DanielAugusto191/87bf42d0f9d1d9ef5cec4225b0700469 to your computer and use it in GitHub Desktop.
mysql connection Ocaml
open Mysql
let () =
let db =
quick_connect ~host:"localhost" ~user:"root" ~password:"{password}"
~database:"{database_name}" ()
in
let result = exec db "SELECT id, name FROM {table_name} LIMIT 5;" in
let rec fetch_rows result =
match fetch result with
| Some row ->
Array.iter
(fun field ->
match field with
| Some value -> Printf.printf "%s " value
| None -> Printf.printf "NULL ")
row;
print_newline ();
fetch_rows result
| None -> ()
in
fetch_rows result;
disconnect db
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment