1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82
|
open Mysql
open Unix
type sql={
s_login : string;
s_pswd : string;
s_host : string;
s_port : string;
s_dbname: string;
}
let retourne_cid c_sql =
(* connexion id *)
let cid =
let db_info = ref {
dbhost = None;
dbname = None;
dbport = None;
dbpwd = None;
dbuser = None
}
in
(* Host *)
(
if String.length c_sql.s_host > 0 then
db_info := {!db_info with dbhost = Some(c_sql.s_host)}
);
(* Database name *)
(
if String.length c_sql.s_dbname > 0 then
db_info := {!db_info with dbname = Some(c_sql.s_dbname)}
);
(* Port *)
(
if String.length c_sql.s_port > 0 then
db_info := {!db_info with dbport = Some(int_of_string c_sql.s_port)}
);
(* Database password *)
(
if String.length c_sql.s_pswd > 0 then
db_info := {!db_info with dbpwd = Some(c_sql.s_pswd)}
);
(* Database login *)
(
if String.length c_sql.s_login > 0 then
db_info := {!db_info with dbuser = Some(c_sql.s_login)}
);
Mysql.connect !db_info
in
cid
let _ =
let sql = {s_login = "root";
s_pswd = "mon_mdp";
s_host = "localhost";
s_port = "";
s_dbname = "ma_base"}
in
let cid = retourne_cid sql in
let query = "insert into rw_test (chaine) values ('cééé')" in
let _ = exec cid query in ();
Mysql.disconnect cid |
Partager