-
Notifications
You must be signed in to change notification settings - Fork 0
Quickstart Guide
Bob Magic II edited this page Feb 19, 2022
·
7 revisions
composer install netherphp/database
To prepare configuration automatically from a JSON file add a LoadFromJSON
call to your application's main configuration.
Nether\Database\ConnectionConfig::LoadFromJSON(sprintf(
'%s/conf/env/%s/netherdb.json',
ProjectRoot,
ENV
));
Multiple servers can be configured by adding more named entries. The Type field is the name of the PDO driver to use.
{
"Default": {
"Type": "mysql",
"Hostname": "hostname",
"Database": "database",
"Username": "username",
"Password": "password"
}
}
Nether\Option::Set([
'Nether.Database.Connections' => [
'Default' => new Nether\Database\ConnectionConfig(
Type: 'mysql',
Hostname: 'hostname',
Database: 'database',
Username: 'username',
Password: 'password'
)
]
]);
This is a super basic example to get in and get a query done without using any of the fancy features. For advanced things see the various other sections of this wiki.
// collect some data and create a tokenised array keyed in the style
// of pdo bound params, so we can let that handle our injection protection.
$Input = [
':ID' => (int)$_POST['ID'],
':Name' => $_POST['Name']
];
// now hit the database with the info.
$Database = new Nether\Database;
$Result = $Database->Query(
'UPDATE Users SET Name=:Name WHERE ID=:ID;',
$Input
);
// decide if we should move on.
if(!$Result->IsOK())
echo $Result->GetError(), PHP_EOL;
else
echo "User {$Input[':ID']} updated.", PHP_EOL;