Skip to content

database class for working on a database using prepared queries with mysqli - by @mulraf

License

Notifications You must be signed in to change notification settings

Osekai/osekai-db

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 

Repository files navigation

osekai-db

database class for working on a database using prepared queries with mysqli - by @mulraf

Usage

execSimpleSelect

Database::execSimpleSelect([string]query)

Selects from database. Should not use user-input

Examples:

Select all from database

Database::execSimpleSelect("SELECT * FROM Medals");

execSelect

Database::execSelect([string]query, [string]types, [array]inputs)

Selects from database using prepared statement. Here is where you use user input

Examples:

Get row from ID

$id = $_GET['id'];
Database::execSelect("SELECT * FROM Users WHERE id = ?", "i", array($id));
// "i" for int

Get row from two different IDs

$osu_id = 2;
$discord_id = 70828730997551104;
Database::execSelect("SELECT * FROM Users WHERE OsuId = ? AND DiscordId = ?", "ii", array($osu_id, $discord_id)); 

execOperation

Database::execOperation([string]query, [string]types, [array]inputs);

Similar to execSelect, though runs an operation

Examples:

Update value in database

$id = 2;
$newUsername = "cool username!";
Database::execOperation("UPDATE `Users` SET `Username` = ? WHERE `UserID` = ?", "si", array($newUsername, $id)); 

Insert pageview into analytics database

// $countryCode = ?;
// $currentApp = ?;
// $urlQuery = ?;
// $url = ?;
Database::execOperation("INSERT INTO StatsPageViews (date, location, app, query, url) VALUES (CURRENT_TIMESTAMP, ?, ?, ?, ?)", "ssss", array($countryCode, $currentApp, $urlQuery, $url));

About

database class for working on a database using prepared queries with mysqli - by @mulraf

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages