我正在尝试使用SWI Prolog(使用ODBC驱动程序)连接到本地MySQL数据库,我收到以下错误
?- [family].
% family compiled 0.00 sec, 264 bytes
true.
?- open_db.
ERROR: ODBC: State S1090: [unixODBC][Driver Manager]Invalid string or buffer length
数据库名称:prolog_test
Prolog Code(family.pl)
open_db :-
odbc_connect('mysql:dbname=prolog_test;host=localhost', _,
[ user('prologuser'),
password('prologpass'),
alias(localhost),
open(once)
]).
children(X) :-
odbc_query(localhost, 'SELECT (lemma) FROM tableName',X).
感谢您的帮助
答案 0 :(得分:1)
我使用较弱的替代odbc_driver_connect,它运作良好:
myodbc_connect_db(Db, Uid, Pwd, Cn) :-
format(atom(S), 'driver=mysql;db=~w;uid=~w;pwd=~w', [Db, Uid, Pwd]),
odbc_driver_connect(S, Cn, [encoding(utf8)]).
根据应用程序的要求,可能是不需要DSN的优势。
答案 1 :(得分:1)
创建文件:/etc/odbc.ini
[ODBC Data Sources]
odbcname = MyODBC 3.51 Driver DSN
[prologtest]
Driver = /usr/lib/odbc/libmyodbc.so
Description = MyODBC 3.51 Driver DSN
SERVER = my.database.server.com
PORT =
USER = USER
Password = XXXXXX
Database = DBNAME
OPTION = 3
SOCKET =
[Default]
Driver = /usr/local/lib/libmyodbc3.so
Description = MyODBC 3.51 Driver DSN
SERVER = localhost
PORT =
USER = root
Password =
Database = test
OPTION = 3
SOCKET =
在我的机器上,libmyodbc.so位于/usr/lib/x86_64-linux-gnu/odbc/libmyodbc.so
将Prolog代码更改为(更接近documentation)
1 open_wordnet :-
2 odbc_connect('prologtest', _,
3 [ user('prologuser'),
4 password('prologpass'),
5 alias(prologa),
6 open(once)
7 ]).
现在我可以对数据库进行查询了