PHP code example of orhanayd / nonedb
1. Go to this page and download the library: Download orhanayd/nonedb 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/ */
orhanayd / nonedb example snippets
$db = new noneDB();
new noneDB();
// Insert
$db->insert("users", ["name" => "John", "age" => 25, "email" => "[email protected] "]);
// Find
$users = $db->find("users", ["name" => "John"]);
// Query Builder with Operators
$results = $db->query("users")
->where([
'age' => ['$gte' => 18, '$lte' => 65],
'status' => 'active'
])
->sort('age', 'desc')
->limit(10)
->get();
// Update
$db->update("users", [
["name" => "John"],
["set" => ["email" => "[email protected] "]]
]);
// Delete
$db->delete("users", ["name" => "John"]);
$db = new noneDB([
'secretKey' => 'your_secure_key',
'dbDir' => '/path/to/db/'
]);
noneDB::setDevMode(true);
$db = new noneDB();
// Comparison operators
$db->query("products")
->where([
'price' => ['$gte' => 100, '$lte' => 500],
'category' => ['$in' => ['electronics', 'gadgets']],
'stock' => ['$gt' => 0]
])
->sort('rating', 'desc')
->limit(20)
->get();
// Pattern matching
$db->query("users")
->where(['email' => ['$like' => 'gmail.com$']])
->get();
// Existence check
$db->query("users")
->where(['phone' => ['$exists' => true]])
->get();
// Create spatial index
$db->createSpatialIndex("restaurants", "location");
// Insert GeoJSON data
$db->insert("restaurants", [
'name' => 'Ottoman Kitchen',
'location' => ['type' => 'Point', 'coordinates' => [28.9784, 41.0082]]
]);
// Find within radius
$nearby = $db->query("restaurants")
->withinDistance('location', 28.9784, 41.0082, 5000) // 5000 meters (5km)
->where(['open_now' => true])
->get();
// Find nearest K
$closest = $db->nearest("restaurants", "location", 28.9784, 41.0082, 10);
// Find in bounding box
$inArea = $db->withinBBox("restaurants", "location", 28.97, 41.00, 29.00, 41.03);