Created
August 21, 2024 20:24
-
-
Save DanielAugusto191/87bf42d0f9d1d9ef5cec4225b0700469 to your computer and use it in GitHub Desktop.
mysql connection Ocaml
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
| 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