1
| %% Author: Administrator
%% Created: 2011-5-15
%% Description: TODO: Add description to test
-module(test).
%%
%% Include files
%%
%%
%% Exported Functions
%%
-export([start/0]).
%%
%% API Functions
%%
%%
%% Local Functions
%%
start() ->
%% Build connection
%% 注意最后一个参数,utf8,支持中文必杀技.
mysql:start_link(connection,"localhost", 3306,"root", "root", "erlang", undefined, utf8),
%% INSERT
_result = mysql:fetch(connection, [<<"INSERT INTO test_table (id, first_name, last_name) VALUES(default, '你好', '世界')">>]),
io:format("Result1: ~p~n", [_result]),
%% SELECT
_result2 = mysql:fetch(connection, [<<"SELECT * FROM test_table;">>]),
io:format("Result2: ~p~n", [_result2]),
%% UPDATE
_result3 = mysql:fetch(connection, [<<"UPDATE test_table SET first_name = 'River' WHERE first_name = 'ZHIQIANG' AND last_name = 'HE';">>]),
io:format("Result3: ~p~n", [_result3]),
%% SELECT
_result4 = mysql:fetch(connection, [<<"SELECT * FROM test_table;">>]),
io:format("Result4: ~p~n", [_result4]),
%% DELETE
_result5 = mysql:fetch(connection, [<<"DELETE FROM test_table WHERE last_name = 'HE' AND first_name = 'River';">>]),
io:format("Result5: ~p~n", [_result5]),
%% SELECT
_result6 = mysql:fetch(connection, [<<"SELECT * FROM test_table;">>]),
io:format("Result6: ~p~n", [_result6]),
ok.
|