{"id":18924144,"url":"https://github.com/hellsan631/logosdb","last_synced_at":"2025-09-09T22:05:10.122Z","repository":{"id":18378635,"uuid":"21559362","full_name":"hellsan631/LogosDB","owner":"hellsan631","description":"A database micro-framework for creating simple DB interaction without the need for a full framework","archived":false,"fork":false,"pushed_at":"2015-05-10T02:52:41.000Z","size":1756,"stargazers_count":1,"open_issues_count":7,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-31T17:31:03.823Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hellsan631.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-07-07T06:35:03.000Z","updated_at":"2021-04-28T21:30:05.000Z","dependencies_parsed_at":"2022-08-04T23:30:36.089Z","dependency_job_id":null,"html_url":"https://github.com/hellsan631/LogosDB","commit_stats":null,"previous_names":[],"tags_count":22,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hellsan631%2FLogosDB","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hellsan631%2FLogosDB/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hellsan631%2FLogosDB/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hellsan631%2FLogosDB/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hellsan631","download_url":"https://codeload.github.com/hellsan631/LogosDB/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239921877,"owners_count":19718842,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-08T11:05:56.399Z","updated_at":"2025-02-20T21:58:00.446Z","avatar_url":"https://github.com/hellsan631.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"LogosDB v 1.5.*\n=======\n[![Build Status](https://travis-ci.org/hellsan631/LogosDB.svg?branch=master)](https://travis-ci.org/hellsan631/LogosDB) [![Code Climate](https://codeclimate.com/github/hellsan631/LogosDB/badges/gpa.svg)](https://codeclimate.com/github/hellsan631/LogosDB)\n\nLogosDB is a database micro-framework for creating simple DB interaction without the need for a full MVC structure.\n\nThe idea is that for small projects, creating APIs, or when you just don't want or need to implement a fully featured\nMVC framework (Phalcon, Laravel, CodeIgniter, Zend), LogosDB has your back. LogosDB is a bare-bones Model Interaction\nFramework for working with objects inside databases.\n\n## Version 1.5.*\n\n1.5.* Introduces Namespaces into the framework. The namespaces reflect the folder hierarchy, and helps when\nusing multiple frameworks. Names and folder structures might shuffle around a bit while 1.5 gets updates.\n\n## Getting Started\n\n### Requirements\n\n```\nRequires PHP 5.5+\nRequires PDO\n```\n\n### Installation (via composer)\n\nInstallation via composer is simple. Just add the following to your composer.json file\n\n```JSON\n{\n    \"require\": {\n        \"hellsan631/logosdb\": \"1.5.*\"\n    }\n}\n```\n\nAfter running a composer update/install command, extend the class with a logos object\n\n```php\nclass User extends Logos\\DB\\MySQL\\Model{\n    public $username;\n    public $email;\n}\n```\n\nand make sure to include your autoloader\n\n```php\ninclude \"./vendor/autoload.php\";\n```\n\nFor those who don't have composer, just download as a zip, and include the autoload file in\nyour php header\n\n### Creating A Model\n\nCreate an object class for each table in your database you want to use this with.\n\n```php\n//example object\nclass User extends Logos\\DB\\MySQL\\Model{\n\n    //public $id; already defined in the Database_Object class.\n\n    public $username;\n    public $email;\n\n}\n```\n\n### Database Setup\n\nWe use the config class, which creates a simpleton, for inputting our DB connection data. Add this somewhere\nin your header (or you can add this to autoload.php)\n\n```php\nuse Logos\\DB\\Config;\n\n//Database settings\nConfig::write('db.host', 'localhost');\nConfig::write('db.name', 'db_name');\nConfig::write('db.user', 'db_user');\nConfig::write('db.password', 'db_pass');\n```\n\n### Database Schema\n\nMySQL\n```\nEach table in your database should have an ID field, which is a incremental primary\nindex. If you want a table to use a date, use the timestamp format, and include\ndate in the name of the field.\n```\n\n## Usage\n\nFor a quick list of classes and what they do, head on over to the database interface\nhttps://github.com/hellsan631/LogosDB/blob/92a702f60fbf8b2e351bfd6f2d505e391d4a894c/lib/Logos/DB/HandlerInterface.php\n\n### Creating a new object in the database\n\nAn object can be either declared as a variable, or statically created\n(which takes less memory and time)\n\n```php\n//Object as a variable\n$user = new User([\"username\" =\u003e \"testing\", \"email\" =\u003e \"email@email.com\"]);\n$user-\u003ecreateNew();\n\n//Same thing, but done statically (returns the ID of the created object)\nUser::createSingle([\"username\" =\u003e \"testing\", \"email\" =\u003e \"email@email.com\"]);\n```\n\n### Creating Many objects to a database\n\nYou can create objects multiple ways.\n\n```php\n//Want to create 100 new identical objects?\nUser::createMultiple([\"username\" =\u003e \"testing\", \"email\" =\u003e \"email@email.com\"], 100);\n\n//want each object to be different?\n$users = [];\n$count = 0;\n\nwhile($count \u003c 100){\n    array_push($users, [\"username\" =\u003e \"testing\",\n                        \"email\" =\u003e \"email@email.com\",\n                        \"other_var\" =\u003e $count]);\n\n    $count++;\n}\n\nUser::createMultiple($users);\n```\n\n### Saving Changes to an object already in the database\n\n```php\n//Saving a single object\nUser::loadSingle([\"id\" =\u003e 10])-\u003esave([\"email\" =\u003e \"newEmail@gmail.com\"]);\n\n//or\n\nUser::saveSingle([\"email\" =\u003e \"newEmail@gmail.com\"], [\"id\" =\u003e 10]);\n\n//saving to multiple objects at the same time\nUser::saveMultiple([\"email\" =\u003e \"newEmail@gmail.com\"], [\"username\" =\u003e \"testing\"]);\n```\n\n### Expanded query syntax\n\nWant to add a limit, orderBy, or groupBy to your query results?\n\n```php\nUser::query('limit', 10);\nUser::query(['orderBy', 'limit'], ['id DESC', 10]);\nUser::query(['orderBy', 'limit'], ['id ASC, username DESC', 10]);\nUser::query(['orderBy' =\u003e 'id ASC', 'limit' =\u003e 10]);\n\n//Add getList to the end of your query to get a list of that classes objects\nUser::query('limit', 100)-\u003egetList();\n\n//how to use min/max for limit\n//Send them in as array!\nUser::query('limit', [0, 10])-\u003egetList();\nUser::query('limit', ['min' =\u003e 0, 'max' =\u003e 10])-\u003egetList();\n\n//Or if you want to use an array to add more,\nUser::query(['limit' =\u003e [0, 10], 'orderBy' =\u003e 'id ASC'])-\u003egetList();\nUser::query(['limit' =\u003e ['min' =\u003e 0, 'max' =\u003e 10], 'orderBy' =\u003e 'id ASC'])-\u003egetList();\n```\n\nAny added limit/orderby/groupby is only added to the next query executed.\nIf you run any two queries in a row , i.e.\n```php\nUser::query('limit', 10);\nUser::loadMultiple($array1);\n\n//limit 10 no longer applies here\nUser::CreateMultiple($array2);\n```\n\nYou need to add the query to each call to the database if you want it to effect that call.\n\nAlso, any time you set a query, the previous query of that type is overwritten.\n\n```php\nUser::query('limit', 10);\nUser::query('orderBy', 'id ASC');\nUser::query('orderBy', 'id DESC');\n\n//would load 10 users in id DESC order\nUser::loadMultiple($array1);\n```\n\n### Automatically Converts JSON\n\nYou can use JSON or an object anywhere you want.\n\n```php\n$JSON_STRING = '{\"username\": \"testing\", \"email\": \"testing@mail.com\"}';\n\n$user = new User($JSON_STRING);//It works!\n\n//Use JSON anywhere!\nUser::newInstance([\"id\" =\u003e 10])-\u003esave($JSON_STRING);\nUser::createMultiple($JSON_STRING, 100);\n```\n\n### Adheres to Model\n\nYou don't have to worry about what your sending into an object, or if you've\ncreated dynamically declared variables in that object\n\n```php\n$JSON_STRING = '{\"username\": \"testing\", \"email\": \"testing@mail.com\", \"size\": \"small\"}';\n\n$user = new User($JSON_STRING);//It works!\n\nvar_dump($user);\n//object(User)[98]\n//    public 'username' =\u003e string 'testing' (length=7)\n//    public 'email' =\u003e string 'testing@mail.com' (length=16)\n\n$user-\u003eupdateObject($JSON_STRING);\n\nvar_dump($user);\n//object(User)[98]\n//    public 'username' =\u003e string 'testing' (length=7)\n//    public 'email' =\u003e string 'testing@mail.com' (length=16)\n//    public 'size' =\u003e string 'small' (length=5)\n\n//Now that the $user has a dynamic variable, lets try and save it.\n\n$user-\u003esave();\n//UPDATE user SET username = :username, email = :email WHERE id = :id\n```\n\n## Security\n\nThere are 3 added security classes that help with php development. The goal is to enhance existing\nPHP 5.5 functionality with industry standard practices, and make them easy to use.\n\n### The Cipher Class\n\nThe Cipher class allows you to encrypt/decrypt text and generate safe random numbers. It does this using\nMCrypt, a built in PHP extension. Currently, keys are one way, but soon that will change.\n\nUse of the Cipher Class is easy. To encrypt something:\n\n```php\n//Send a secure key to the cipher class.\n$cipher = new Cipher(\"s3cur3k3y\");\n\necho $cipher-\u003eencrypt(\"Hello World!\");\n\n//outputs \"kRTIR6qDGYNumkoAMfwWMGNVPIUoODr0kvFMCmPDynM=\"\n```\n\nIf you want to then decrypt\n\n```php\necho $cipher-\u003edecrypt(\"kRTIR6qDGYNumkoAMfwWMGNVPIUoODr0kvFMCmPDynM=\");\n\n//outputs \"Hello World!\"\n```\n\nYou can also get a random key from Cipher. Its highly recommended that you use cipher in place of any other\nrandom key/number generators for security, as Cipher uses \"openssl_random_pseudo_bytes()\", which is the most\nsecure way in php to get a random string of data.\n\n```php\n//You can send in a length of key into the getRandomKey method, or just leave it blank for a default length of 22.\n$randomKey = Cipher::getRandomKey();\n```\n\n### The Password Class\n\nThe password class helps secure user passwords using PHP 5.5 built in BCrypt implementation. Its by far the most\nsecure way of storing passwords, and all passwords should be stored this way.\n\nFor an implementation of this, I recommend looking at one of my other projects, and the way it handles user creation.\n\nTo Create A New User and save his password correctly:\n\nnewUser.php\n```php\n$newUser = new User($_POST);\n\nif($newUser-\u003ecreateNew())\n    $_SESSION['result'] = \"Successfully added new User\";\nelse\n    $_SESSION['result'] = \"Unable to add new User\";\n\nheader(\"Location: ./index.php\");\n```\n\nTo Login with a user\n\nauth.php\n```php\n$user = User::loadSingle([\"username\" =\u003e $_POST['username']]);\n\nif(!$user \u0026\u0026 strlen($_POST['username']) \u003e 6)\n    $user = User::loadSingle([\"email\" =\u003e $_POST['username']]);\n\nif(!$user){\n    $_SESSION['result'] = \"Couldn't find a user with that username/email\";\n}else{\n    if($user-\u003edoAuth($_POST['password'])){\n\n        $_SESSION['result'] = \"Login Successful\";\n        $_SESSION['user'] = $user-\u003etoArray();\n\n    }else{\n\n        $_SESSION['result'] = \"Incorrect Password\";\n\n    }\n}\n\nheader(\"Location: ../login.php\");\n```\n\nAnd then the user class that handles it all\n\nclass.user.php\n```php\n\nclass User extends Logos\\DB\\MySQL\\Model{\n\n    public $username;\n    public $email;\n    public $password;\n    public $salt;\n    public $admin;\n    public $auth_key;\n    public $company_id;\n\n    public function createNew(){\n\n        $password = new Password($this-\u003epassword);\n\n        $this-\u003epassword = $password-\u003egetKey();\n        $this-\u003esalt = $password-\u003egetSalt();\n\n        return parent::createNew();\n\n    }\n\n    public function verifyLogin($password){\n        $passwordCheck = new Password($this-\u003epassword, array('salt' =\u003e $this-\u003esalt, 'hashed' =\u003e true));\n\n        return $passwordCheck-\u003echeckPassword($password);\n    }\n\n    public function verifyAuth(){\n        if(!isset($_SESSION['auth_key']))\n            return false;\n\n        if($this-\u003eauth_key !== $_SESSION['auth_key'])\n            return false;\n\n        return true;\n    }\n\n    public function verifyAdmin(){\n        if($this-\u003eadmin === 0)\n            return false;\n\n        return true;\n    }\n\n    public static function deAuth(){\n        foreach($_SESSION as $key =\u003e $value){\n            if($key !== \"result\" || $key !== \"Result\" || $key !== \"RESULT\")\n                unset($_SESSION[$key]);\n        }\n\n        return true;\n    }\n\n    public function doAuth($password, $level = 0){\n        if($this-\u003everifyLogin($password) === false)\n            return false;\n\n        if((int) $level === 1){\n            if($this-\u003everifyAdmin())\n                return true;\n        }else{\n            if($this-\u003everifyAuth())\n                return true;\n        }\n\n        if($this-\u003eadmin === 0 \u0026\u0026 $level === 1)\n            return false;\n\n        $_SESSION['auth_key'] = $this-\u003eauth_key = Cipher::getRandomKey();\n\n        if($level === 1)\n            $_SESSION['admin_key'] = $this-\u003eauth_key;\n\n        return ($this-\u003esave() !== false) ? true : false;\n    }\n}\n\n```\n\n### The Iron Class\n\nIron Class helps protect against Cross Site Request Forgery attacks. Doing this can be a bit complicated, but\nwith this class, the implementation is pretty straight forward.\n\nFor Post Requests (example login form)\n\nlogin.php\n```php\n\u003c?php\n\n    $iron = Iron::getInstance();\n\n?\u003e\n\n\u003cform id=\"login\" action=\"auth.php\" method=\"post\"\u003e\n    \u003cinput type=\"text\" name=\"username\" placeholder=\"Username\" /\u003e\n    \u003cinput type=\"password\" name=\"password\" placeholder=\"Password\" /\u003e\n    \u003c?php\n       echo $iron-\u003egenerate_post_token(); //echos a post input with a new random key\n    ?\u003e\n\u003c/form\u003e\n\n```\n\nauth.php\n```php\n$iron = Iron::getInstance();\n\nif($iron-\u003echeck_token() !== false){\n\n    //its safe, you can do user authentication in here\n\n}else{\n\n    //warning, auth isn't safe. You should log the IP and lock down the system.\n\n}\n```\n\nIf you wanted to protect your GET requests as well\n\nInfo.php\n```php\n    $iron = Iron::getInstance();\n\n    $requestURL = \"www.example.com/user.php?id=100123\".$iron-\u003egenerate_get_token();\n\n    getUserData($requestURL);\n```\n\nuser.php\n```php\n\n$iron = Iron::getInstance();\n\nif($iron-\u003echeck_token() !== false){\n\n    //its safe, you can do user authentication in here\n\n}else{\n\n    //warning, auth isn't safe. You should log the IP and lock down the system.\n\n}\n```\n\n## Contributing\n\nPlease feel free to fork, push, pull and all that other good Git stuff!\n\n# Thanks\n\n(Expanding on this readme at a later date)\n\nVisit my blog: \nhttp://mathew-kleppin.com/blog-page/\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhellsan631%2Flogosdb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhellsan631%2Flogosdb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhellsan631%2Flogosdb/lists"}