Erlang的mysql示例 [英] Erlang mysql example
问题描述
只是想知道是否有人可以给出一个使用erlang-mysql模块的工作示例( http://code.google.com/p/erlang-mysql-driver/ )。
Just wondering if anyone could give a working example of using the erlang-mysql module (http://code.google.com/p/erlang-mysql-driver/).
我是erlang的新手,我正在尝试用几个erlang批处理代替一些旧的脚本。我可以连接到数据库,甚至完成一个查询,但我不知道如何使用结果。这是我目前拥有的:
I am new to erlang and I am trying to replace some old scripts with a few erlang batch processes. I am able to connect to the DB and even complete a query, but I am not sure how I use the results. Here is what I currently have:
-include("../include/mysql.hrl").
...
mysql:start_link(p1, "IP-ADDRESS", "erlang", "PASSWORD", "DATABASE"),
Result1 = mysql:fetch(p1, <<"SELECT * FROM users">>),
io:format("Result1: ~p~n", [Result1]),
...
我还有一个准备好的声明,我也使用只得到一行(如果存在),这将有助于知道如何访问结果,
I also have a prepared statement that I am also using to get just one row (if it exists) and it would be helpful to know how to access the results on that as well
推荐答案
这是在源代码 mysql.erl
:
您的结果将是 {data,MySQLRes}
。
FieldInfo = mysql:get_result_field_info(MysqlRes)
,其中 FieldInfo
是一个列表 {Table,Field,Length,Name}
元组。
FieldInfo = mysql:get_result_field_info(MysqlRes)
, where FieldInfo
is a list of {Table, Field, Length, Name}
tuples.
AllRows = mysql: get_result_rows(MysqlRes)
,其中 AllRows
是一个列表列表,每个表示一行。
AllRows = mysql:get_result_rows(MysqlRes)
, where AllRows
is a list of lists, each representing a row.
这篇关于Erlang的mysql示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!