Gothic Online Forums
MySQL 0.2 - Printable Version

+- Gothic Online Forums (https://archive.gothic-online.com)
+-- Forum: Scripting (English) (https://archive.gothic-online.com/forum-11.html)
+--- Forum: Resources (https://archive.gothic-online.com/forum-14.html)
+---- Forum: Modules (https://archive.gothic-online.com/forum-32.html)
+---- Thread: MySQL 0.2 (/thread-25.html)



MySQL 0.2 - Bimbol - 09.10.2015

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


RE: MySQL 0.1 - Bimbol - 31.08.2016

MySQL module was updated, and now work on version 0.0.3 Wink


RE: MySQL 0.1 - Bimbol - 29.10.2016

MySQL module update to 0.2!
Changes:
- Fixed crashes when row has NULL value
- Added controling parameter types


RE: MySQL 0.2 - Profesores - 07.10.2019

Hi, I've been created 0.3 version last year, and now I would like to share it with you Big Grin

Changelog:
-[EDITED] mysql_query - now return true, when query was successful, or false when there's errors.
-[ADDED] string(or false when there's problem) mysql_real_escape_string(handler, string to escape) - I don't think I need to expalin it Tongue

Binares (windows/linux): https://mega.nz/#!qLhgmQSI!2ZnVY8_VVhxaNQJUdVwYj0Um3i55dd8ygkTwZ_ErYnM
Source-Code: https://mega.nz/#!TH5mHIpT!exXcTYtV3gXXZJQXEBv710UNP8HQssU28IKn_J1U530