Thread Rating:
  • 3 Vote(s) - 4.67 Average
  • 1
  • 2
  • 3
  • 4
  • 5
MySQL 0.2
#1
MySQL bind is a third-party module,  which provides Squirrel functions to access data from MySQL databases. More information about MySQL database you will find on the internet. If you looking for SQL language tutorial look here: http://www.w3schools.com/sql/

Implementation:
Add mysql to config as script.
Code:
<module src="MySQL.dll" type="server" /> // For windows
<module src="MySQL.so" type="server" /> // For linux

Squirrel function:
[return value = function(params)]
null/userpointer handler = mysql_connect(string host, string user, string password, string database, int port = 3306)
mysql_close(userpointer handler)
null/userpointer result = mysql_query(userpointer handler, string query)
null/int rowCount = mysql_num_rows(userpointer result)
null/int fieldCount = mysql_num_fields(userpointer result)
null/array data = mysql_fetch_row(userpointer result)
null/table data = mysql_fetch_assoc(userpointer result)
bool ping = mysql_ping(userpointer handler)
mysql_free_result(userpointer result)
null/string error = mysql_error(userpointer handler)
null/int errorId = mysql_errno(userpointer handler)

Short example:
Squirrel Script
  1. local handler = mysql_connect("localhost", "root", "", "db_test");
  2. if (handler)
  3. {
  4. local result = mysql_query(handler, "SELECT * FROM mdb_users");
  5.  
  6. if (result)
  7. {
  8. print("Query done " + mysql_num_rows(result));
  9. local row = mysql_fetch_row(result);
  10. if (row)
  11. {
  12. foreach (val in row)
  13. {
  14. print(type(val) + " " + val);
  15. }
  16. }
  17.  
  18. mysql_free_result(result);
  19. }
  20. else
  21. {
  22. print(mysql_error(handler));
  23. print("Error ID: " + mysql_errno(handler));
  24. }
  25.  
  26. result = mysql_query(handler, "SELECT * FROM mdb_users");
  27.  
  28. if (result)
  29. {
  30. print("Query done " + mysql_num_fields(result));
  31. local row_assoc = mysql_fetch_assoc(result);
  32. if (row_assoc)
  33. {
  34. print(row_assoc["username"] + " " + row_assoc["email"]);
  35. }
  36.  
  37. mysql_free_result(result);
  38. }
  39. else
  40. {
  41. print(mysql_error(handler));
  42. print("Error ID: " + mysql_errno(handler));
  43. }
  44.  
  45. mysql_close(handler);
  46. }



Download version 0.2:
Binares: https://bitbucket.org/Bimbol/sqmysql/downloads
Source code: https://bitbucket.org/Bimbol/sqmysql/src
Reply


Messages In This Thread
MySQL 0.2 - by Bimbol - 09.10.2015, 23:36
RE: MySQL 0.1 - by Bimbol - 31.08.2016, 00:54
RE: MySQL 0.1 - by Bimbol - 29.10.2016, 20:15
RE: MySQL 0.2 - by Profesores - 07.10.2019, 04:39

Forum Jump:


Users browsing this thread: 1 Guest(s)