Skip to content

Commit 6dc393b

Browse files
committed
Initial Release
0 parents  commit 6dc393b

File tree

9 files changed

+1466
-0
lines changed

9 files changed

+1466
-0
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/vendor/
2+
composer.lock
3+
.vscode
4+
.idea

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Kyutefox
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
## :rocket: KyutePDO: Lightweight and Customizable PHP Library
2+
3+
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.
4+
5+
### Features
6+
7+
- Lightweight and easy to use
8+
- Customizable and highly configurable
9+
- Supports multiple databases (MySQL, PostgreSQL, SQLite, and Oracle)
10+
- Provides a simple and intuitive API for executing queries and managing transactions
11+
- Offers a caching system to improve performance
12+
- Supports prepared statements to prevent SQL injection attacks
13+
14+
### :page_with_curl: Documentation
15+
16+
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.
17+
18+
[KyutePDO Full Docs](https://kyutefox.com/product/kyutepdo)
19+
20+
### :star2: Contribution
21+
If this project has helped you make sure to leave a start as a part of your contribution
22+
23+
### :purple_heart: Maintainer
24+
- [GitHub](https://github.com/razoo-choudhary)
25+
- [Twitter](https://twitter.com/razoo_choudhary)
26+
- [Linktree](https://linktr.ee/razoo_choudhary)

composer.json

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"name": "kyutefox/kyutepdo",
3+
"description": "A PDO-based PHP library for easy and efficient database management",
4+
"type": "library",
5+
"homepage": "https://kyutefox.com/product/kyutepdo",
6+
"version": "1.0.0",
7+
"keywords": [
8+
"pdo",
9+
"database",
10+
"php",
11+
"library"
12+
],
13+
"license": "MIT",
14+
"authors": [
15+
{
16+
"name": "Raju choudhary",
17+
"homepage": "https://github.com/razoo-choudhary"
18+
}
19+
],
20+
"require": {
21+
"php": "^7.4 || ^8.0",
22+
"ext-pdo": "*",
23+
"ext-json": "*"
24+
},
25+
"autoload": {
26+
"psr-4": {
27+
"Kyutefox\\KyutePDO\\": "src/"
28+
}
29+
},
30+
"require-dev": {
31+
"phpunit/phpunit": "^9.5"
32+
},
33+
"config": {
34+
"sort-packages": true
35+
},
36+
"minimum-stability": "dev",
37+
"prefer-stable": true
38+
}

src/Config/Connection.php

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<?php
2+
3+
namespace Kyutefox\KyutePDO\Config;
4+
5+
use PDO;
6+
7+
class Connection
8+
{
9+
private string $host;
10+
private string $driver;
11+
private string $charset;
12+
private string $collation;
13+
private string $port;
14+
private string $name;
15+
private string $user;
16+
private string $pass;
17+
private string $dsn;
18+
private array $config;
19+
20+
public function __construct(array $config)
21+
{
22+
$this->driver = !empty($config["db_driver"]) ? $config["db_driver"] : 'mysql';
23+
$this->host = !empty($config["db_host"]) ? $config["db_host"] : 'localhost';
24+
$this->charset = !empty($config["db_charset"]) ? $config["db_charset"] : 'utf8mb4';
25+
$this->collation = !empty($config["db_collation"]) ? $config["db_collation"] : 'utf8mb4_unicode_ci';
26+
$this->port = !empty($config["db_port"]) ? (strstr($config["db_port"], ':') ? explode(':', $config["db_port"])[1] : "") : '3306';
27+
$this->user = !empty($config["db_user"]) ? $config["db_user"] : 'root';
28+
$this->pass = !empty($config["db_pass"]) ? $config["db_pass"] : '';
29+
$this->name = !empty($config["db_name"]) ? $config["db_name"] : '';
30+
$this->config = $config["db_config"] ?? [];
31+
}
32+
33+
public function init(): ?PDO
34+
{
35+
if (in_array($this->driver, ['mysql', 'pgsql']))
36+
{
37+
$this->dsn = $this->driver . ':host=' . str_replace(':' . $this->port, '', $this->host) . ';port=' . $this->port . ';dbname=' . $this->name;
38+
}
39+
40+
if ($this->driver == 'sqlite') $this->dsn = $this->driver . ':' . $this->name;
41+
if ($this->driver == "oracle") $this->dsn = 'oci:dbname=' . $this->name . '/' . $this->host;
42+
43+
return $this->connect($this->dsn);
44+
}
45+
46+
private function connect(string $dataSource)
47+
{
48+
try
49+
{
50+
$pdo = new \PDO($dataSource, $this->user, $this->pass, $this->config);
51+
$pdo->exec("SET NAMES '" . $this->charset . "' COLLATE '" . $this->collation . "'");
52+
$pdo->exec("SET CHARACTER SET '" . $this->charset . "'");
53+
$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
54+
}
55+
catch(\PDOException $e)
56+
{
57+
die("Specified database connection couldn't be started with PDO. " . $e->getMessage());
58+
}
59+
60+
return $pdo;
61+
}
62+
}

src/Interfaces/KyutePDOInterface.php

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?php
2+
3+
namespace Kyutefox\KyutePDO\Interfaces;
4+
5+
interface KyutePDOInterface
6+
{
7+
/**
8+
* @param null $type
9+
* @param null $argument
10+
* @return mixed
11+
*/
12+
13+
public function get($type = null, $argument = null);
14+
15+
/**
16+
* @param null $type
17+
* @param null $argument
18+
* @return mixed
19+
*/
20+
21+
public function getAll($type = null, $argument = null);
22+
23+
/**
24+
* @param array $data
25+
* @param false $type
26+
* @return mixed
27+
*/
28+
29+
public function update(array $data, $type = false);
30+
31+
/**
32+
* @param array $data
33+
* @param false $type
34+
* @return mixed
35+
*/
36+
37+
public function insert(array $data, $type = false);
38+
39+
/**
40+
* @param false $type
41+
* @return mixed
42+
*/
43+
44+
public function delete($type = false);
45+
}

0 commit comments

Comments
 (0)