OPT 项目试用 erlang-mysql-driver

st1. 获取源码

    git clone https://github.com/fxl0206/erlang-mysql-dirver

    fork from  https://github.com/fxl0206/erlang-mysql-driver

    为了方便编译导入erlang库做了如下修改:

     Makefile:

                  PROJECT=mysql

                  include erlang.mk

    mysql.app.src

                    {application, mysql,[

                      {description, "MySQL Library"},

                      {vsn, "34"},

                      {modules, []},

                      {registered, [mysql]},

                      {applications, [

                            kernel,

                            stdlib

                      ]},

                      {mod, {mysql_app, []}},

                      {env, []}

                    ]}.

st2.  导入到erlang lib

   cd erlang-mysql-driver

   make

   mkdir -p /usr/local/erlang/lib/erlang/lib/mysql-1.0.0

   cp -R ebin /usr/local/erlang/lib/erlang/lib/mysql-1.0.0

   cp -R include  /usr/local/erlang/lib/erlang/lib/mysql-1.0.0

st3.在opt项目中使用配置

    在app配置文件中included dirver            

        {application, xxxxxx, [

                {description, ""},

                {vsn, "1"},

                {modules, []},

                {registered, [xxxxx]},

                {included_applications,[mysql]},%这里

                {applications, [

                kernel,

                stdlib

                ]},

                {mod, {xxxxxx, []}},

                {env, []}

                ]}.

st4 代码案例

 可以了,打开erlang的终端测试一下

mysql:start_link(conn, "数据库IP或域名", 3306, "root", "密码", "数据库名称", undefined, utf8).
{data, Result} = mysql:fetch(conn, <<"select * from t_users">>).
Rows = mysql:get_result_rows(Result).



你可能感兴趣的:(OPT 项目试用 erlang-mysql-driver)