Erlang/OTP Forums

Author Message

<  Advanced Erlang/OTP  ~  erlang, yaws , mysql

Seb
Posted: Thu Sep 03, 2009 4:45 pm Reply with quote
Joined: 10 Mar 2008 Posts: 5 Location: Canada
Hi,
This should be super easy :
I have a YAWS server and a MySQL server running under Ubuntu. I want to establish a connection from an erlang-html page to the MySQL server. Here's what I have:

Code:


<html>
<erl>
application:start(odbc).
ConnString = "Driver={MySQL ODBC 5.1 Driver};Server=localhost;Database=test; User=root;Password=ace152;Option=3;".
{ok, Conn} = odbc:connect(ConnString, []).
Results = odbc:sql_query(Conn, "SELECT * FROM test_table").

out(A)->{html,"Something here."}.

</erl>
</htmL>

So, Why doesn't this work ? Any ideas ?

[/code]
View user's profile Send private message
baryluk
Posted: Fri Sep 04, 2009 11:36 am Reply with quote
User Joined: 05 Aug 2009 Posts: 48
Please read cerfully http://yaws.hyber.org/dynamic.yaws

First put everything into out/1 function. If you will check log files you will probably see compilation errors now, explaing what is wrong. I don't know what is your knowledge about Erlang, but remember that if you put statments into one function, they should be spearated (statments) by comma, not period.

Second I would not recomend calling application:start(odbc) on each request. It will not hurt you if application is already started, but you should probably start it somewhere else. (for test you can do it in erlang shell: it should return {ok,Pid} or {error,{already_started, Pid}} )

The best way is to run your code step by step in console:
Code:

application:start(odbc).
ConnString = "Driver={MySQL ODBC 5.1 Driver};Server=localhost;Database=test; User=root;Password=ace152;Option=3;".
{ok, Conn} = odbc:connect(ConnString, []).
Results = odbc:sql_query(Conn, "SELECT * FROM test_table").


And i hope ace152 isn't your root password...

_________________
Witold Baryluk

Erlang Training and Consulting Ltd
http://www.erlang-consulting.com
View user's profile Send private message

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum