PHP code example of ggedde / spry-db
1. Go to this page and download the library: Download ggedde/spry-db library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
ggedde / spry-db example snippets
$item = Spry::db()->get('items', '*', ['id' => 123]);
$items = Spry::db()->select('items', '*', ['date[>]' => '2020-01-01']);
$insertResponse = Spry::db()->insert('items', ['name' => 'test', 'date' => '2020-01-01']);
$updateResponse = Spry::db()->update('items', ['name' => 'newtest'], ['id' => 123]);
$deleteResponse = Spry::db()->delete('items', ['id' => 123]);
$config->dbProvider = 'Spry\\SpryProvider\\SpryDB';
$config->db = [
'database_type' => 'mysql',
'database_name' => '',
'server' => 'localhost',
'username' => '',
'password' => '',
'charset' => 'utf8',
'port' => 3306,
'prefix' => 'api_x_', // Should change this to be someting Unique
'schema' => [
'tables' => [
'users' => [
'columns' => [
'name' => [
'type' => 'string'
],
'email' => [
'type' => 'string'
],
]
]
]
]
];
'schema' => [
'tables' => [
'users' => [
'columns' => [
'name' => [
'type' => 'string'
],
'email' => [
'type' => 'string',
'unique' => true
],
'amount' => [
'type' => 'number',
'default' => 0
],
'status' => [
'type' => 'enum',
'options' => ['pending','active','completed','archived',''],
],
'start_date' => [
'type' => 'datetime',
'default' => 'CURRENT_TIMESTAMP'
],
]
]
]
]
'schema' => [
'tables' => [
'users' => [
'use_id' => false,
'timestamps' => false
]
]
]
'email' => [
'type' => 'string',
'unique' => true
]
'email' => [
'type' => 'string',
'unique' => [
'name',
'phone'
]
]