Skip to content

Commit

Permalink
Initial Release
Browse files Browse the repository at this point in the history
  • Loading branch information
MrJukeman committed Apr 11, 2023
0 parents commit 6dc393b
Show file tree
Hide file tree
Showing 9 changed files with 1,466 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/vendor/
composer.lock
.vscode
.idea
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Kyutefox

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
## :rocket: KyutePDO: Lightweight and Customizable PHP Library

KyutePDO is a powerful and easy-to-use PHP library that allows developers to work with relational databases seamlessly. It is built on top of PDO, a PHP extension that provides a consistent interface for accessing different types of databases.

### Features

- Lightweight and easy to use
- Customizable and highly configurable
- Supports multiple databases (MySQL, PostgreSQL, SQLite, and Oracle)
- Provides a simple and intuitive API for executing queries and managing transactions
- Offers a caching system to improve performance
- Supports prepared statements to prevent SQL injection attacks

### :page_with_curl: Documentation

KyutePDO comes with comprehensive documentation that provides an in-depth overview of its features, configuration options, and usage examples. The documentation is available online, making it easy for developers to access and use it.

[KyutePDO Full Docs](https://kyutefox.com/product/kyutepdo)

### :star2: Contribution
If this project has helped you make sure to leave a start as a part of your contribution

### :purple_heart: Maintainer
- [GitHub](https://github.com/razoo-choudhary)
- [Twitter](https://twitter.com/razoo_choudhary)
- [Linktree](https://linktr.ee/razoo_choudhary)
38 changes: 38 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "kyutefox/kyutepdo",
"description": "A PDO-based PHP library for easy and efficient database management",
"type": "library",
"homepage": "https://kyutefox.com/product/kyutepdo",
"version": "1.0.0",
"keywords": [
"pdo",
"database",
"php",
"library"
],
"license": "MIT",
"authors": [
{
"name": "Raju choudhary",
"homepage": "https://github.com/razoo-choudhary"
}
],
"require": {
"php": "^7.4 || ^8.0",
"ext-pdo": "*",
"ext-json": "*"
},
"autoload": {
"psr-4": {
"Kyutefox\\KyutePDO\\": "src/"
}
},
"require-dev": {
"phpunit/phpunit": "^9.5"
},
"config": {
"sort-packages": true
},
"minimum-stability": "dev",
"prefer-stable": true
}
62 changes: 62 additions & 0 deletions src/Config/Connection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

namespace Kyutefox\KyutePDO\Config;

use PDO;

class Connection
{
private string $host;
private string $driver;
private string $charset;
private string $collation;
private string $port;
private string $name;
private string $user;
private string $pass;
private string $dsn;
private array $config;

public function __construct(array $config)
{
$this->driver = !empty($config["db_driver"]) ? $config["db_driver"] : 'mysql';
$this->host = !empty($config["db_host"]) ? $config["db_host"] : 'localhost';
$this->charset = !empty($config["db_charset"]) ? $config["db_charset"] : 'utf8mb4';
$this->collation = !empty($config["db_collation"]) ? $config["db_collation"] : 'utf8mb4_unicode_ci';
$this->port = !empty($config["db_port"]) ? (strstr($config["db_port"], ':') ? explode(':', $config["db_port"])[1] : "") : '3306';
$this->user = !empty($config["db_user"]) ? $config["db_user"] : 'root';
$this->pass = !empty($config["db_pass"]) ? $config["db_pass"] : '';
$this->name = !empty($config["db_name"]) ? $config["db_name"] : '';
$this->config = $config["db_config"] ?? [];
}

public function init(): ?PDO
{
if (in_array($this->driver, ['mysql', 'pgsql']))
{
$this->dsn = $this->driver . ':host=' . str_replace(':' . $this->port, '', $this->host) . ';port=' . $this->port . ';dbname=' . $this->name;
}

if ($this->driver == 'sqlite') $this->dsn = $this->driver . ':' . $this->name;
if ($this->driver == "oracle") $this->dsn = 'oci:dbname=' . $this->name . '/' . $this->host;

return $this->connect($this->dsn);
}

private function connect(string $dataSource)
{
try
{
$pdo = new \PDO($dataSource, $this->user, $this->pass, $this->config);
$pdo->exec("SET NAMES '" . $this->charset . "' COLLATE '" . $this->collation . "'");
$pdo->exec("SET CHARACTER SET '" . $this->charset . "'");
$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
}
catch(\PDOException $e)
{
die("Specified database connection couldn't be started with PDO. " . $e->getMessage());
}

return $pdo;
}
}
45 changes: 45 additions & 0 deletions src/Interfaces/KyutePDOInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

namespace Kyutefox\KyutePDO\Interfaces;

interface KyutePDOInterface
{
/**
* @param null $type
* @param null $argument
* @return mixed
*/

public function get($type = null, $argument = null);

/**
* @param null $type
* @param null $argument
* @return mixed
*/

public function getAll($type = null, $argument = null);

/**
* @param array $data
* @param false $type
* @return mixed
*/

public function update(array $data, $type = false);

/**
* @param array $data
* @param false $type
* @return mixed
*/

public function insert(array $data, $type = false);

/**
* @param false $type
* @return mixed
*/

public function delete($type = false);
}
Loading

0 comments on commit 6dc393b

Please sign in to comment.