Pastebin
API
tools
faq
paste
Login
Sign up
Please fix the following errors:
New Paste
Syntax Highlighting
Placeholders Placeholders allow for query parameters to be safely executed, preventing common SQL injection methods. Parameters can be passed an an array or map (referred to as named named parameters). local identifier = 'license:abc123' local group = 'admin' MySQL.scalar('SELECT `username` FROM `users` WHERE `identifier` = ? AND `group` = ?', { identifier, group }) -- Named placeholders (deprecated) MySQL.scalar('SELECT `username` FROM `users` WHERE `identifier` = @identifier AND `group` = @group', { group = group identifier = identifier }) These are distinct from prepared statements which are handled by the MySQL server; you can use MySQL.prepare for more optimised and secure queries. Insert Inserts a new entry into the database and returns the insert id for the row, if valid. Promise local id = MySQL.insert.await('INSERT INTO `users` (identifier, firstname, lastname) VALUES (?, ?, ?)', { identifier, firstName, lastName }) print(id) Aliases MySQL.Sync.insert exports.ghmattimysql.executeSync exports.oxmysql.insert_async Callback MySQL.insert('INSERT INTO `users` (identifier, firstname, lastname) VALUES (?, ?, ?)', { identifier, firstName, lastName }, function(id) print(id) end) Aliases MySQL.Async.insert exports.ghmattimysql.execute exports.oxmysql.insert Prepare Prepare can be used to execute frequently called queries faster and accepts multiple sets of parameters to be used with a single query. Date will not return the datestring commonly used in FiveM TINYINT 1 and BIT will not return a boolean You can only use ? value placeholders, ?? column placeholders and named placeholders will throw an error Unlike rawExecute, the SELECT statement will return a column, row, or array of rows depending on the number of columns and rows selected. Promise local response = MySQL.prepare.await('SELECT `firstname`, `lastname` FROM `users` WHERE `identifier` = ?', { identifier }) print(json.encode(response, { indent = true, sort_keys = true })) Aliases exports.oxmysql.prepare_async Callback MySQL.prepare('SELECT `firstname`, `lastname` FROM `users` WHERE `identifier` = ?', { identifier }, function(response) print(json.encode(response, { indent = true, sort_keys = true })) end) Aliases exports.oxmysql.prepare Query When selecting data, returns all matching rows and columns; otherwise, returns data like insertId, affectedRows, etc. Promise local response = MySQL.query.await('SELECT `firstname`, `lastname` FROM `users` WHERE `identifier` = ?', { identifier }) if response then for i = 1, #response do local row = response[i] print(row.firstname, row.lastname) end end Aliases MySQL.Sync.fetchAll exports.ghmattimysql.execute exports.oxmysql.query_async Callback MySQL.query('SELECT `firstname`, `lastname` FROM `users` WHERE `identifier` = ?', { identifier }, function(response) if response then for i = 1, #response do local row = response[i] print(row.firstname, row.lastname) end end end) Aliases MySQL.Async.fetchAll exports.ghmattimysql.execute exports.oxmysql.query RawExecute rawExecute can be used to execute frequently called queries faster and accepts multiple sets of parameters to be used with a single query. Date will not return the datestring commonly used in FiveM TINYINT 1 and BIT will not return a boolean You can only use ? value placeholders, ?? column placeholders and named placeholders will throw an error Unlike prepare, the SELECT statement will always return an array of rows. When using SELECT, the return value will match query, single, or scalar depending on the number of columns and rows selected. Promise local response = MySQL.rawExecute.await('SELECT `firstname`, `lastname` FROM `users` WHERE `identifier` = ?', { identifier }) print(json.encode(response, { indent = true, sort_keys = true })) Aliases exports.oxmysql.rawExecute_async Callback MySQL.rawExecute('SELECT `firstname`, `lastname` FROM `users` WHERE `identifier` = ?', { identifier }, function(response) print(json.encode(response, { indent = true, sort_keys = true })) end) Aliases exports.oxmysql.rawExecute Scalar Returns the first column for a single row. Promise local firstName = MySQL.scalar.await('SELECT `firstname` FROM `users` WHERE `identifier` = ? LIMIT 1', { identifier }) print(firstName) Aliases MySQL.Sync.fetchScalar exports.ghmattimysql.scalar exports.oxmysql.scalar_async Callback MySQL.scalar('SELECT `firstname` FROM `users` WHERE `identifier` = ? LIMIT 1', { identifier }, function(firstName) print(firstName) end) Aliases MySQL.Async.fetchScalar exports.ghmattimysql.scalar exports.oxmysql.scalar Single Returns all selected columns for a single row. Promise local row = MySQL.single.await('SELECT `firstname`, `lastname` FROM `users` WHERE `identifier` = ? LIMIT 1', { identifier }) if not row then return end print(row.firstname, row.lastname) Aliases exports.oxmysql.single_async Callback MySQL.single('SELECT `firstname`, `lastname` FROM `users` WHERE `identifier` = ? LIMIT 1', { identifier }, function(row) if not row then return end print(row.firstname, row.lastname) end) Aliases exports.oxmysql.single Transaction A transaction executes multiple queries and commits them only if all succeed. If one fails, none of the queries are committed. The return value is a boolean, which is the result of the transaction. Specific format When using this format, you must pass an array containing sets of queries and parameters to the transaction method. In this case, your queries do not necessarily match and the values are unique to each query. -- You might rename "values" as "parameters" for mysql-async compatibility. local queries = { { query = 'INSERT INTO `test` (id) VALUES (?)', values = { 1 }}, { query = 'INSERT INTO `test` (id, name) VALUES (?, ?)', values = { 2, 'bob' }}, } -- You can also pass an array of arrays. local queries = { { 'INSERT INTO `test` (id) VALUES (?)', { 1 } }, { 'INSERT INTO `test` (id, name) VALUES (?, ?)', { 2, 'bob' } }, } Shared format When using this format, you must pass an array containing queries and a set containing shared parameters to the transaction method. In this case, your queries do not necessarily match and the values are unique to each query. -- You might rename "values" as "parameters" for mysql-async compatibility. local queries = { 'INSERT INTO `test` (id, name) VALUES (@someid, @somename)', 'SET `name` = @newname IN `test` WHERE `id` = @someid' } local values = { someid = 2, somename = 'John Doe', newname = 'John Notdoe' } Promise local success = MySQL.transaction.await(queries, values --[[leave nil for specific format]]) print(success) Aliases MySQL.Sync.transaction exports.ghmattimysql.transaction exports.oxmysql.transaction_async Callback -- specific MySQL.transaction(queries, values, function(success) print(success) end) -- shared MySQL.transaction(queries, function(success) print(success) end) Aliases MySQL.Async.transaction exports.ghmattimysql.transaction exports.oxmysql.transaction Transaction Isolation Level This can be set through the convar mysql_transaction_isolation_level, and is an integer ranging from 1-4. The default value is 2. Convar Value Result 1 Repeatable Read 2 Read Committed 3 Read Uncommitted 4 Serializable Update Returns the number of rows affected by the query. Promise local affectedRows = MySQL.update.await('UPDATE users SET firstname = ? WHERE identifier = ?', { newName, identifier }) print(affectedRows) Aliases MySQL.Sync.execute exports.ghmattimysql.executeSync exports.oxmysql.update_async Callback MySQL.update('UPDATE users SET firstname = ? WHERE identifier = ?', { newName, identifier }, function(affectedRows) print(affectedRows) end) Aliases MySQL.Async.execute exports.ghmattimysql.execute exports.oxmysql.update
Optional Paste Settings
Category:
None
Cryptocurrency
Cybersecurity
Fixit
Food
Gaming
Haiku
Help
History
Housing
Jokes
Legal
Money
Movies
Music
Pets
Photo
Science
Software
Source Code
Spirit
Sports
Travel
TV
Writing
Tags:
Syntax Highlighting:
None
Bash
C
C#
C++
CSS
HTML
JSON
Java
JavaScript
Lua
Markdown (PRO members only)
Objective C
PHP
Perl
Python
Ruby
Swift
4CS
6502 ACME Cross Assembler
6502 Kick Assembler
6502 TASM/64TASS
ABAP
AIMMS
ALGOL 68
APT Sources
ARM
ASM (NASM)
ASP
ActionScript
ActionScript 3
Ada
Apache Log
AppleScript
Arduino
Asymptote
AutoIt
Autohotkey
Avisynth
Awk
BASCOM AVR
BNF
BOO
Bash
Basic4GL
Batch
BibTeX
Blitz Basic
Blitz3D
BlitzMax
BrainFuck
C
C (WinAPI)
C Intermediate Language
C for Macs
C#
C++
C++ (WinAPI)
C++ (with Qt extensions)
C: Loadrunner
CAD DCL
CAD Lisp
CFDG
CMake
COBOL
CSS
Ceylon
ChaiScript
Chapel
Clojure
Clone C
Clone C++
CoffeeScript
ColdFusion
Cuesheet
D
DCL
DCPU-16
DCS
DIV
DOT
Dart
Delphi
Delphi Prism (Oxygene)
Diff
E
ECMAScript
EPC
Easytrieve
Eiffel
Email
Erlang
Euphoria
F#
FO Language
Falcon
Filemaker
Formula One
Fortran
FreeBasic
FreeSWITCH
GAMBAS
GDB
GDScript
Game Maker
Genero
Genie
GetText
Go
Godot GLSL
Groovy
GwBasic
HQ9 Plus
HTML
HTML 5
Haskell
Haxe
HicEst
IDL
INI file
INTERCAL
IO
ISPF Panel Definition
Icon
Inno Script
J
JCL
JSON
Java
Java 5
JavaScript
Julia
KSP (Kontakt Script)
KiXtart
Kotlin
LDIF
LLVM
LOL Code
LScript
Latex
Liberty BASIC
Linden Scripting
Lisp
Loco Basic
Logtalk
Lotus Formulas
Lotus Script
Lua
M68000 Assembler
MIX Assembler
MK-61/52
MPASM
MXML
MagikSF
Make
MapBasic
Markdown (PRO members only)
MatLab
Mercury
MetaPost
Modula 2
Modula 3
Motorola 68000 HiSoft Dev
MySQL
Nagios
NetRexx
Nginx
Nim
NullSoft Installer
OCaml
OCaml Brief
Oberon 2
Objeck Programming Langua
Objective C
Octave
Open Object Rexx
OpenBSD PACKET FILTER
OpenGL Shading
Openoffice BASIC
Oracle 11
Oracle 8
Oz
PARI/GP
PCRE
PHP
PHP Brief
PL/I
PL/SQL
POV-Ray
ParaSail
Pascal
Pawn
Per
Perl
Perl 6
Phix
Pic 16
Pike
Pixel Bender
PostScript
PostgreSQL
PowerBuilder
PowerShell
ProFTPd
Progress
Prolog
Properties
ProvideX
Puppet
PureBasic
PyCon
Python
Python for S60
QBasic
QML
R
RBScript
REBOL
REG
RPM Spec
Racket
Rails
Rexx
Robots
Roff Manpage
Ruby
Ruby Gnuplot
Rust
SAS
SCL
SPARK
SPARQL
SQF
SQL
SSH Config
Scala
Scheme
Scilab
SdlBasic
Smalltalk
Smarty
StandardML
StoneScript
SuperCollider
Swift
SystemVerilog
T-SQL
TCL
TeXgraph
Tera Term
TypeScript
TypoScript
UPC
Unicon
UnrealScript
Urbi
VB.NET
VBScript
VHDL
VIM
Vala
Vedit
VeriLog
Visual Pro Log
VisualBasic
VisualFoxPro
WHOIS
WhiteSpace
Winbatch
XBasic
XML
XPP
Xojo
Xorg Config
YAML
YARA
Z80 Assembler
ZXBasic
autoconf
jQuery
mIRC
newLISP
q/kdb+
thinBasic
Paste Expiration:
Never
Burn after read
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Exposure:
Public
Unlisted
Private
Folder:
(members only)
Password
NEW
Enabled
Disabled
Burn after read
NEW
Paste Name / Title:
Create New Paste
Hello
Guest
Sign Up
or
Login
Sign in with Facebook
Sign in with Twitter
Sign in with Google
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Public Pastes
Cooking Recipe
3 min ago | 6.19 KB
Cooking Recipe
5 min ago | 6.20 KB
Cooking Recipe
8 min ago | 6.18 KB
⭐ Exploit Documentation ⭐
CSS | 40 min ago | 1.04 KB
This month smells like money
CSS | 40 min ago | 1.04 KB
✅ API Flaw Money Method
CSS | 41 min ago | 1.04 KB
Cooking Recipe
1 hour ago | 6.11 KB
Cooking Recipe
1 hour ago | 6.10 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the
Cookies Policy
.
OK, I Understand
Not a member of Pastebin yet?
Sign Up
, it unlocks many cool features!