con = assert(mysql:connect(db_name, db_user, db_pass, db_host)) cur = assert(con:execute("SELECT version()"))
Core.SendToAll("<mysql> MYSQL driver version is: "..luasql._MYSQLVERSION) Core.SendToAll("<mysql> "..luasql._COPYRIGHT) Core.SendToAll("<mysql> "..luasql._DESCRIPTION) Core.SendToAll("<mysql> "..luasql._VERSION)
con = assert(mysql:connect(db_name, db_user, db_pass, db_host))
function ChatArrival(tUser,sData) local _,_,sCmd = sData:find"%b<>%s+(%S+)|" if sCmd == "+1" then for id, name, nick in rows(con, "SELECT * FROM `jos_users`") do Core.SendToAll("ID -> "..id.."\nNAME -> "..name.."\nNICK -> "..nick) end return true end end
function rows (connection, sql_statement) local cursor = assert (connection:execute (sql_statement)) return function () return cursor:fetch() end end
con:close() mysql:close()
Âûøå â ïðèìåðå ÿ ïîäêëþ÷àëñÿ ê áàçå äàííûõ áåñïëàòíîé CMS Joomla è âûâîäèë Id, Èìÿ ïîëüçîâàòåëÿ è åãî Íèê.
Âñÿ íåîáõîäèìàÿ èíôîðìàöèÿ î ïðîåêòå LuaSQL - http://mydc.ru/r/?http://www.keplerproject.org/luasql/manual.html#introduction
# make gcc -O2 -Wall -Wmissing-prototypes -Wmissing-declarations -ansi -pedantic -I../compat/src -I/opt/local/include -I/usr/local/include -c -o src/luasql.o src/luasql.c gcc -O2 -Wall -Wmissing-prototypes -Wmissing-declarations -ansi -pedantic -I../compat/src -I/opt/local/include -I/usr/local/include -c -o src/ls_sqlite3.o src/ls_sqlite3.c src/ls_sqlite3.c:14:21: error: sqlite3.h: Íåò òàêîãî ôàéëà èëè êàòàëîãà src/ls_sqlite3.c:41: îøèáêà: expected specifier-qualifier-list before ‘sqlite3’ src/ls_sqlite3.c:51: îøèáêà: expected specifier-qualifier-list before ‘sqlite3_stmt’ src/ls_sqlite3.c: In function ‘finalize’: src/ls_sqlite3.c:95: ïðåäóïðåæäåíèå: implicit declaration of function ‘sqlite3_finalize’ src/ls_sqlite3.c:95: îøèáêà: ‘cur_data’ has no member named ‘sql_vm’ src/ls_sqlite3.c:95: îøèáêà: ‘SQLITE_OK’ undeclared (first use in this function) src/ls_sqlite3.c:95: îøèáêà: (Each undeclared identifier is reported only once src/ls_sqlite3.c:95: îøèáêà: for each function it appears in.) src/ls_sqlite3.c:97: ïðåäóïðåæäåíèå: implicit declaration of function ‘sqlite3_errmsg’ src/ls_sqlite3.c:97: ïðåäóïðåæäåíèå: implicit declaration of function ‘sqlite3_db_handle’ src/ls_sqlite3.c:97: îøèáêà: ‘cur_data’ has no member named ‘sql_vm’ src/ls_sqlite3.c:97: ïðåäóïðåæäåíèå: assignment makes pointer from integer without a cast src/ls_sqlite3.c:98: îøèáêà: ‘cur_data’ has no member named ‘sql_vm’ src/ls_sqlite3.c:105: îøèáêà: ‘cur_data’ has no member named ‘sql_vm’ src/ls_sqlite3.c: In function ‘cur_fetch’: src/ls_sqlite3.c:116: îøèáêà: ‘sqlite3_stmt’ undeclared (first use in this function) src/ls_sqlite3.c:116: îøèáêà: ‘vm’ undeclared (first use in this function) src/ls_sqlite3.c:116: îøèáêà: ‘cur_data’ has no member named ‘sql_vm’ src/ls_sqlite3.c:117: ïðåäóïðåæäåíèå: ISO C90 forbids mixed declarations and code src/ls_sqlite3.c:122: ïðåäóïðåæäåíèå: implicit declaration of function ‘sqlite3_step’ src/ls_sqlite3.c:125: îøèáêà: ‘SQLITE_DONE’ undeclared (first use in this function) src/ls_sqlite3.c:128: îøèáêà: ‘SQLITE_ROW’ undeclared (first use in this function) src/ls_sqlite3.c:141: ïðåäóïðåæäåíèå: implicit declaration of function ‘sqlite3_column_text’ src/ls_sqlite3.c:141: ïðåäóïðåæäåíèå: ïðèâåäåíèå ê òèïó óêàçàòåëÿ îò öåëîãî äðóãîãî ðàçìåðà src/ls_sqlite3.c:153: ïðåäóïðåæäåíèå: ïðèâåäåíèå ê òèïó óêàçàòåëÿ îò öåëîãî äðóãîãî ðàçìåðà src/ls_sqlite3.c:165: ïðåäóïðåæäåíèå: ïðèâåäåíèå ê òèïó óêàçàòåëÿ îò öåëîãî äðóãîãî ðàçìåðà src/ls_sqlite3.c: In function ‘cur_close’: src/ls_sqlite3.c:187: îøèáêà: ‘cur_data’ has no member named ‘sql_vm’ src/ls_sqlite3.c: Íà âåðõíåì óðîâíå: src/ls_sqlite3.c:230: îøèáêà: expected declaration specifiers or ‘...’ before ‘sqlite3_stmt’ src/ls_sqlite3.c: In function ‘create_cursor’: src/ls_sqlite3.c:245: îøèáêà: ‘cur_data’ has no member named ‘sql_vm’ src/ls_sqlite3.c:245: îøèáêà: ‘sql_vm’ undeclared (first use in this function) src/ls_sqlite3.c:254: ïðåäóïðåæäåíèå: implicit declaration of function ‘sqlite3_column_name’ src/ls_sqlite3.c:254: ïðåäóïðåæäåíèå: passing argument 2 of ‘lua_pushstring’ makes pointer from integer without a cast src/ls_sqlite3.c:263: ïðåäóïðåæäåíèå: implicit declaration of function ‘sqlite3_column_decltype’ src/ls_sqlite3.c:263: ïðåäóïðåæäåíèå: passing argument 2 of ‘lua_pushstring’ makes pointer from integer without a cast src/ls_sqlite3.c: In function ‘conn_close’: src/ls_sqlite3.c:291: ïðåäóïðåæäåíèå: implicit declaration of function ‘sqlite3_close’ src/ls_sqlite3.c:291: îøèáêà: ‘conn_data’ has no member named ‘sql_conn’ src/ls_sqlite3.c: In function ‘conn_escape’: src/ls_sqlite3.c:299: ïðåäóïðåæäåíèå: implicit declaration of function ‘sqlite3_mprintf’ src/ls_sqlite3.c:299: ïðåäóïðåæäåíèå: initialization makes pointer from integer without a cast src/ls_sqlite3.c:307: ïðåäóïðåæäåíèå: implicit declaration of function ‘sqlite3_free’ src/ls_sqlite3.c: In function ‘conn_execute’: src/ls_sqlite3.c:322: îøèáêà: ‘sqlite3_stmt’ undeclared (first use in this function) src/ls_sqlite3.c:322: îøèáêà: ‘vm’ undeclared (first use in this function) src/ls_sqlite3.c:323: ïðåäóïðåæäåíèå: ISO C90 forbids mixed declarations and code src/ls_sqlite3.c:327: ïðåäóïðåæäåíèå: implicit declaration of function ‘sqlite3_prepare’ src/ls_sqlite3.c:327: îøèáêà: ‘conn_data’ has no member named ‘sql_conn’ src/ls_sqlite3.c:328: îøèáêà: ‘SQLITE_OK’ undeclared (first use in this function) src/ls_sqlite3.c:330: îøèáêà: ‘conn_data’ has no member named ‘sql_conn’ src/ls_sqlite3.c:330: ïðåäóïðåæäåíèå: assignment makes pointer from integer without a cast src/ls_sqlite3.c:340: ïðåäóïðåæäåíèå: implicit declaration of function ‘sqlite3_column_count’ src/ls_sqlite3.c:343: îøèáêà: ‘SQLITE_ROW’ undeclared (first use in this function) src/ls_sqlite3.c:343: îøèáêà: ‘SQLITE_DONE’ undeclared (first use in this function) src/ls_sqlite3.c:345: ïðåäóïðåæäåíèå: implicit declaration of function ‘sqlite3_reset’ src/ls_sqlite3.c:346: îøèáêà: ñëèøêîì ìíîãî àðãóìåíòîâ â âûçîâå ôóíêöèè ‘create_cursor’ src/ls_sqlite3.c:353: ïðåäóïðåæäåíèå: implicit declaration of function ‘sqlite3_changes’ src/ls_sqlite3.c:353: îøèáêà: ‘conn_data’ has no member named ‘sql_conn’ src/ls_sqlite3.c:358: ïðåäóïðåæäåíèå: assignment makes pointer from integer without a cast src/ls_sqlite3.c: In function ‘conn_commit’: src/ls_sqlite3.c:380: ïðåäóïðåæäåíèå: implicit declaration of function ‘sqlite3_exec’ src/ls_sqlite3.c:380: îøèáêà: ‘conn_data’ has no member named ‘sql_conn’ src/ls_sqlite3.c:382: îøèáêà: ‘SQLITE_OK’ undeclared (first use in this function) src/ls_sqlite3.c: In function ‘conn_rollback’: src/ls_sqlite3.c:408: îøèáêà: ‘conn_data’ has no member named ‘sql_conn’ src/ls_sqlite3.c:409: îøèáêà: ‘SQLITE_OK’ undeclared (first use in this function) src/ls_sqlite3.c: In function ‘conn_getlastautoid’: src/ls_sqlite3.c:425: ïðåäóïðåæäåíèå: implicit declaration of function ‘sqlite3_last_insert_rowid’ src/ls_sqlite3.c:425: îøèáêà: ‘conn_data’ has no member named ‘sql_conn’ src/ls_sqlite3.c: In function ‘conn_setautocommit’: src/ls_sqlite3.c:442: îøèáêà: ‘conn_data’ has no member named ‘sql_conn’ src/ls_sqlite3.c:449: îøèáêà: ‘conn_data’ has no member named ‘sql_conn’ src/ls_sqlite3.c:450: îøèáêà: ‘SQLITE_OK’ undeclared (first use in this function) src/ls_sqlite3.c: Íà âåðõíåì óðîâíå: src/ls_sqlite3.c:467: îøèáêà: expected declaration specifiers or ‘...’ before ‘sqlite3’ src/ls_sqlite3.c: In function ‘create_connection’: src/ls_sqlite3.c:476: îøèáêà: ‘conn_data’ has no member named ‘sql_conn’ src/ls_sqlite3.c:476: îøèáêà: ‘sql_conn’ undeclared (first use in this function) src/ls_sqlite3.c: In function ‘env_connect’: src/ls_sqlite3.c:490: îøèáêà: ‘sqlite3’ undeclared (first use in this function) src/ls_sqlite3.c:490: îøèáêà: ‘conn’ undeclared (first use in this function) src/ls_sqlite3.c:491: ïðåäóïðåæäåíèå: ISO C90 forbids mixed declarations and code src/ls_sqlite3.c:495: ïðåäóïðåæäåíèå: implicit declaration of function ‘sqlite3_open’ src/ls_sqlite3.c:496: îøèáêà: ‘SQLITE_OK’ undeclared (first use in this function) src/ls_sqlite3.c:498: ïðåäóïðåæäåíèå: assignment makes pointer from integer without a cast src/ls_sqlite3.c:506: îøèáêà: ñëèøêîì ìíîãî àðãóìåíòîâ â âûçîâå ôóíêöèè ‘create_connection’ make: *** [src/ls_sqlite3.o] Îøèáêà 1
Àâòîð: mariner 23.2.2011, 14:04
äëÿ íà÷àëà îòêðûòü õîòÿ áû êîíôèã ñáîðêè.
Àâòîð: Parad0x 23.2.2011, 23:01
Ïîòîðîïèëñÿ ñ íàïèñàíèåì ïîñòà Îòêðûë êîíôèã, ïîäïðàâèë, äàëåå make è ïîëó÷àåì òàê:
console
Êîä
# make export MACOSX_DEPLOYMENT_TARGET="10.3"; gcc -O2 -Wall -Wmissing-prototypes -Wmissing-declarations -ansi -pedantic -I/root/compat-5.1r5 -I/usr/include/mysql -I/usr/local/include -o src/mysql.so -shared src/luasql.o src/ls_mysql.o -L/usr/lib/mysql -lmysqlclient -lz /usr/bin/ld: src/luasql.o: relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC src/luasql.o: could not read symbols: Bad value collect2: âûïîëíåíèå ld çàâåðøèëîñü ñ êîäîì âîçâðàòà 1 make: *** [src/mysql.so] Îøèáêà 1
config
Êîä
# Driver (leave uncommented ONLY the line with the name of the driver) T= mysql #T= oci8 #T= odbc #T= postgres #T= sqlite #T=sqlite3
/usr/bin/ld: src/luasql.o: relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC
È îïÿòü ïîòîðîïèëñÿ. Äîïèøè â ýòî ìåòñî
Êîä
# OS dependent LIB_OPTION= -shared #for Linux
-fPIC
Àâòîð: Parad0x 23.2.2011, 23:17
Ñïàñèáî çà áûñòðûé îòâåò, íî:
console
Êîä
# make export MACOSX_DEPLOYMENT_TARGET="10.3"; gcc -O2 -Wall -Wmissing-prototypes -Wmissing-declarations -ansi -pedantic -I/root/compat-5.1r5 -I/usr/include/mysql -I/usr/local/include -o src/mysql.so -shared -fPIC src/luasql.o src/ls_mysql.o -L/usr/lib/mysql -lmysqlclient -lz /usr/bin/ld: src/luasql.o: relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC src/luasql.o: could not read symbols: Bad value collect2: âûïîëíåíèå ld çàâåðøèëîñü ñ êîäîì âîçâðàòà 1 make: *** [src/mysql.so] Îøèáêà 1
ò.å. íè÷åãî íå ïîìåíÿëîñü
Àâòîð: mariner 24.2.2011, 2:03
À make clean ñäåëàë êàê äîáàâèë?)
Àâòîð: Parad0x 24.2.2011, 19:58
åõ... â ëèíóêñå íîâè÷åê, êàê-òî è çàáûëîñü. âîò êàê áû ñäåëàë
Êîä
gcc -O2 -Wall -Wmissing-prototypes -Wmissing-declarations -ansi -pedantic -I/root/compat-5.1r5 -I/usr/include/mysql -I/usr/local/include -c -o src/luasql.o src/luasql.c gcc -O2 -Wall -Wmissing-prototypes -Wmissing-declarations -ansi -pedantic -I/root/compat-5.1r5 -I/usr/include/mysql -I/usr/local/include -c -o src/ls_mysql.o src/ls_mysql.c In file included from src/ls_mysql.c:19: /usr/include/mysql/mysql.h:129: ïðåäóïðåæäåíèå: ISO C90 íå ïîääåðæèâàåò òèï ‘long long’ export MACOSX_DEPLOYMENT_TARGET="10.3"; gcc -O2 -Wall -Wmissing-prototypes -Wmissing-declarations -ansi -pedantic -I/root/compat-5.1r5 -I/usr/include/mysql -I/usr/local/include -o src/mysql.so -shared -fPIC src/luasql.o src/ls_mysql.o -L/usr/lib/mysql -lmysqlclient -lz /usr/bin/ld: src/luasql.o: relocation R_X86_64_32 against `a local symbol' can not be used when making a shared object; recompile with -fPIC src/luasql.o: could not read symbols: Bad value collect2: âûïîëíåíèå ld çàâåðøèëîñü ñ êîäîì âîçâðàòà 1 make: *** [src/mysql.so] Îøèáêà 1
21.09.2013 08:09:12 - /var/ptokax/scripts/ajaxchat.lua:198: attempt to index global 'luasql' (a nil value) 21.09.2013 08:09:12 - /var/ptokax/scripts/ajaxchat.lua:235: attempt to index global 'env' (a nil value)
os debian 7.1 mysql 5.5.31 lua 5.1 ptokax 4.1.2 Ïîäñêàæèòå ïîæàëóéñòà êàê ñ ýòèì áîðîòüñÿ.