Difference between revisions of "LSModule:MySQL"
Jump to navigation
Jump to search
(17 intermediate revisions by 3 users not shown) | |||
Line 5: | Line 5: | ||
* [[LSModule:MySQL:mysql (Object Type)|mysql]] | * [[LSModule:MySQL:mysql (Object Type)|mysql]] | ||
* [[LSModule:MySQL:mysqlresult (Object Type)|mysqlresult]] | * [[LSModule:MySQL:mysqlresult (Object Type)|mysqlresult]] | ||
+ | |||
+ | == Example Usage == | ||
+ | /* | ||
+ | * Require MySQL module during preprocessing, so the variables can be created as part of script structure | ||
+ | * instead of using DeclareVariable | ||
+ | */ | ||
+ | #if !${LavishScript:LoadModule[MySQL](exists)} | ||
+ | #error MySQL module for LavishScript required. | ||
+ | #endif | ||
+ | |||
+ | function main() | ||
+ | { | ||
+ | variable mysql DB | ||
+ | variable mysqlresult Result | ||
+ | |||
+ | /* | ||
+ | * Connect to db on localhost | ||
+ | * user/pass: jimmy/jimmys password | ||
+ | * DB name: db_562 | ||
+ | */ | ||
+ | if !${DB:Connect[localhost,jimmy,jimmys password,db_562](exists)} | ||
+ | { | ||
+ | echo Could not connect to MySQL database | ||
+ | return | ||
+ | } | ||
+ | |||
+ | /* | ||
+ | * SELECT user_id,user_name,user_email FROM table_users | ||
+ | * Place result in Result object | ||
+ | */ | ||
+ | if !${DB:Query["SELECT user_id,user_name,user_email FROM table_users",Result](exists)} | ||
+ | { | ||
+ | echo Query failed | ||
+ | return | ||
+ | } | ||
+ | |||
+ | while ${Result:FetchRow(exists)} | ||
+ | { | ||
+ | echo User ${Result.GetString[user_id]}: ${Result.GetString[user_name]} | ||
+ | echo -- Email Address: ${Result.GetString[user_email]} | ||
+ | } | ||
+ | } | ||
== Downloads == | == Downloads == | ||
− | === Ready to | + | === Ready to Run === |
− | * [ | + | : Place the following files in your "InnerSpace\LavishScript Modules" folder |
− | + | * [https://svn.isxgames.com/isxScripts/Projects/LSMMySQL/Bin/Release/LSMMySQL.dll https://svn.isxgames.com/isxScripts/Projects/LSMMySQL/Bin/Release/LSMMySQL.dll] | |
+ | * [https://svn.isxgames.com/isxScripts/Projects/LSMMySQL/mysql-connector-c-6.1.1-win32/lib/libmysql.dll https://svn.isxgames.com/isxScripts/Projects/LSMMySQL/mysql-connector-c-6.1.1-win32/lib/libmysql.dll] | ||
=== Source Code === | === Source Code === | ||
− | * [ | + | : Visual Studio 2012 Project, using Visual Studio 2010 platform, and MySQL Connector 6.1.1 (included) |
+ | * [https://svn.isxgames.com/isxScripts/Projects/LSMMySQL SVN https://svn.isxgames.com/isxScripts/Projects/LSMMySQL] | ||
== See Also == | == See Also == |
Latest revision as of 19:17, 26 August 2013
Contents
Overview
This open-source module provides support for MySQL database interaction
Object Types
Example Usage
/* * Require MySQL module during preprocessing, so the variables can be created as part of script structure * instead of using DeclareVariable */ #if !${LavishScript:LoadModule[MySQL](exists)} #error MySQL module for LavishScript required. #endif function main() { variable mysql DB variable mysqlresult Result /* * Connect to db on localhost * user/pass: jimmy/jimmys password * DB name: db_562 */ if !${DB:Connect[localhost,jimmy,jimmys password,db_562](exists)} { echo Could not connect to MySQL database return } /* * SELECT user_id,user_name,user_email FROM table_users * Place result in Result object */ if !${DB:Query["SELECT user_id,user_name,user_email FROM table_users",Result](exists)} { echo Query failed return } while ${Result:FetchRow(exists)} { echo User ${Result.GetString[user_id]}: ${Result.GetString[user_name]} echo -- Email Address: ${Result.GetString[user_email]} } }
Downloads
Ready to Run
- Place the following files in your "InnerSpace\LavishScript Modules" folder
- https://svn.isxgames.com/isxScripts/Projects/LSMMySQL/Bin/Release/LSMMySQL.dll
- https://svn.isxgames.com/isxScripts/Projects/LSMMySQL/mysql-connector-c-6.1.1-win32/lib/libmysql.dll
Source Code
- Visual Studio 2012 Project, using Visual Studio 2010 platform, and MySQL Connector 6.1.1 (included)