Erlang数据库-(一)Erlang与Mysql的连接

来源:互联网 发布:库课软件怎么样 编辑:程序博客网 时间:2024/05/16 09:44

下载:http://download.csdn.net/detail/hjhjava/7088277

把该文件的东西全部编译好,然后根据下面的解释就可以操作Mysql的。很简单~大笑


<span style="font-size:12px;">-record(row,{a1 = 0, a2=0}).%% 第一个参数是该链接的名字(根据它来操作Mysql),第二参数是本机号(ip地址)%% ,第三个参数是端口,第四个参数是数据库账号%% ,第五个参数是数据库密码,第六个参数是数据库(这个数据库要先数据库中创建啊!!!)    mysql:start_link(p1, "localhost", 3306, root, root, test1,fun(_, _, _, _) -> ok end),   %% 第一个参数是该链接的名字(根据它来操作Mysql,由 mysql:start_link来定义的)%% ,第四个参数是数据库账号,第二参数是本机号(ip地址)%% ,第五个参数是数据库密码,第六个参数是数据库(这个数据库要先数据库中创建啊!!!)    mysql:connect(p1, "localhost", undefined, root, root, test1, true),       %% fetch主要是操作数据库的。“<<>>”里面写sql语句就可以了。    mysql:fetch(p1, <<"drop table if exists memory_test">>),mysql:fetch(p1, <<"drop table if exists innoDB_test">>),    %% 表为memory的内存数据表    mysql:fetch(p1, <<"create table memory_test</span>(id int not null auto_increment,                                               a1 int not null,                                               a2 int not null,       primary key (id)) engine = memory">>),%% 表为innodb   mysql:fetch(p1, <<"create table innoDB_test (id int not null auto_increment,                                               a1 int not null,                                               a2 int not null,       primary key (id)) engine = innodb">>).


一些基本操作:

        %对表mysql_memory插入数据。         mysql:fetch(p1, <<"insert into memory_test(a1,a2)">>)
        %测试innodb类型表的写入时间%对表mysql_innoDB插入数据。        mysql:fetch(p1, <<"insert into innoDB_test (a1,a2)">>)%% 在mysql_memory中读取id等于Str的行mysql:fetch(p1, list_to_binary("select * from  memory_test where id = " ++ Str))










0 0
原创粉丝点击