diff --git a/README.md b/README.md index 4c6b84a..f7c1382 100644 --- a/README.md +++ b/README.md @@ -1,21 +1,29 @@ -# php-mysql-connectors +# Slvler - php-mysql-connectors +Mysql driver development that can be used on the php side -PHP Mysql Connectors +## Installation + +To install this package tou can use composer: + +```bash + composer require slvler/mysql-connectors +``` + +## Usage -Initialize ------------- ```php - + +use slvler\mysqlconnectors\Constant; +use slvler\mysqlconnectors\Config\Method; +use slvler\mysqlconnectors\Database\DatabaseController; + + +$Constant = new Constant(); + +$db = new DatabaseController($Constant->showDBHost(), $Constant->showDBName(), $Constant->showDBUser(), $Constant->showDBPassword(), $Constant->showConnection()); + ``` @@ -51,19 +59,17 @@ $data = Array ); ``` -```php -Insert Method -Insert($tableName,$data); -?> -``` +### Insert Method +```php -#### Update Method (TableName, Id = array() , Data = array()): +$methodInsert = $method->Insert($tableName,$data); +``` +#### Update Method (TableName, Id = array() , Data = array()): TableName, Id , Data: @@ -82,19 +88,15 @@ $data = Array ); ``` -```php -Update Method -Update($tableName', $id, $data); -?> -``` - - +### Update Method +```php +$methodUpdate = $method->Update($tableName', $id, $data); +``` -#### Delete Method (TableName, Id = array()): +### Delete Method (TableName, Id = array()): TableName, Id: @@ -107,16 +109,17 @@ $Id = array( ``` +### Delete Method + ```php -Delete Method -Delete($tableName,$id); -?> + ``` -#### Select_all Method (TableName): +### Select_all Method (TableName): TableName: @@ -124,17 +127,18 @@ TableName: $tableName = "Orders"; ``` +### Select_all Method + ```php -Select_all Method -Select_all($tableName); -?> + ``` -#### Select_ch Method (TableName, Data = array()): +### Select_ch Method (TableName, Data = array()): TableName, Data: @@ -148,11 +152,12 @@ $data = Array ``` +### Select_ch Method + ```php -Select_ch Method -Select_ch($tableName,$data); -?> + ``` @@ -180,17 +185,28 @@ $if = Array ``` + +### Select_wh Method + ```php -Select_wh Method -Select_wh($tableName, $data, $conn, $if); -?> + ``` +### Testing + +```bash +vendor\bin\phpunit +``` +## Credits +- [slvler](https://github.com/slvler) +## License +The MIT License (MIT). Please see [License File](https://github.com/slvler/slvler/blob/main/LICENSE.md) for more information. \ No newline at end of file diff --git a/composer.json b/composer.json new file mode 100644 index 0000000..63c11f0 --- /dev/null +++ b/composer.json @@ -0,0 +1,31 @@ +{ + "name": "slvler/mysql-connectors", + "license": "MIT", + "description": "Mysql driver development that can be used on the php side", + "type": "package", + "authors": [ + { + "name": "slvler", + "email": "slvler@proton.me" + } + ], + "autoload": { + "psr-4": { + "slvler\\mysqlconnectors\\": "src/" + } + }, + "autoload-dev": { + "psr-4": { + "slvler\\mysqlconnectors\\Tests\\": "tests/" + } + }, + "require": {}, + "require-dev": { + "phpunit/phpunit": "^9.5" + }, + "scripts": { + "test": "vendor/bin/phpunit tests" + }, + "minimum-stability": "dev", + "prefer-stable": true +} \ No newline at end of file diff --git a/example/index.php b/example/index.php new file mode 100644 index 0000000..aa63e30 --- /dev/null +++ b/example/index.php @@ -0,0 +1,30 @@ +showDBHost(), $Constant->showDBName(), $Constant->showDBUser(), $Constant->showDBPassword(), $Constant->showConnection()); + +$connection = $db->MysqlConnection(); +$method = new Method($connection); + +$example = $method->Select_all("orders"); + + + +$data = array( + 'ShipName' => "deneme", + 'ShipAddress' => "deneme", + 'ShipCity' => "deneme" +); + +$method = $method->Insert("orders",$data); + +?> \ No newline at end of file diff --git a/phpunit.xml b/phpunit.xml new file mode 100644 index 0000000..495c3a6 --- /dev/null +++ b/phpunit.xml @@ -0,0 +1,12 @@ + + + + + tests + + + \ No newline at end of file diff --git a/src/qwerty/Config/Method.php b/src/Config/Method.php similarity index 93% rename from src/qwerty/Config/Method.php rename to src/Config/Method.php index 67e2454..74febfd 100644 --- a/src/qwerty/Config/Method.php +++ b/src/Config/Method.php @@ -1,46 +1,44 @@ - \ No newline at end of file diff --git a/src/qwerty/Config/Sql.php b/src/Config/Sql.php similarity index 94% rename from src/qwerty/Config/Sql.php rename to src/Config/Sql.php index bd74ad6..fb68683 100644 --- a/src/qwerty/Config/Sql.php +++ b/src/Config/Sql.php @@ -1,158 +1,158 @@ -connetction = $connetction; -} - -public function Select_ch($table,$data = array()) -{ - array_keys($data); - $qt = ""; - foreach(array_merge($data) as $item){ - $qt .= $item.", "; - } - $res = rtrim($qt,", "); - - $this->sql = "Select ".$res." from ".$table; - $this->query = $this->connetction->prepare($this->sql); - $this->query->execute(); - - while($this->rt = $this->query->fetchAll()) { - return $this->rt; - }; - // TODO: Implement Select_ch() method. -} - -public function Select_all($table) - { - $this->sql = "Select * from ".$table; - $this->query = $this->connetction->prepare($this->sql); - $this->query->execute(); - - while($this->rt = $this->query->fetchAll()) { - return $this->rt; - }; - - - } - - public function Select_wh($table,$data = array(),$con = array(),$if = array()){ - - - $q = ""; - $i = 0; - $b = 1; - foreach($data as $x => $val) { - $q .= " $x ".$con[$i]." $val ".$if[$b - 1]; - $i++; - } - - $res = rtrim($q,"AND"); - - - $this->sql = "SELECT * FROM ".$table." WHERE ". $res; - - $this->query = $this->connetction->prepare($this->sql); - $this->query->execute(); - - while($this->rt = $this->query->fetchAll()) { - return $this->rt; - }; - - - - } - -public function Insert($table, $data = array()) -{ - $quote = ""; - foreach (array_keys($data) as $item){ - $quote .= $item." = :". "$item, "; - } - $res = rtrim($quote,", "); - - $this->sql = "INSERT INTO ".$table." SET " . $res; - $this->query = $this->connetction->prepare($this->sql); - $this->rt = $this->query->execute($data); - if ($this->rt) { - //return $this->connection->lastInsertId(); - return $this->rt; - } - - - // TODO: Implement Insert() method. -} - -public function Update($table, $id = array(), $data = array()) - { - - $quete = ""; - - foreach($data as $x => $val) { - $quete .= "$x = '$val', "; - } - - $res = rtrim($quete,", "); - - $wher = ""; - - foreach($id as $x => $val) { - $wher .= "$x = $val, "; - } - - $wh = rtrim($wher,", "); - - - $this->sql = "UPDATE ".$table." SET " . $res . " WHERE ".$wh.";"; - - $this->query = $this->connetction->prepare($this->sql); - - $this->rt = $this->query->execute(); - if ($this->rt) { - return $this->rt; - - } - - } - - public function Delete($table, $id = array()) - { - - $wher = ""; - - foreach($id as $x => $val) { - $wher .= "$x = $val, "; - } - - $wh = rtrim($wher,", "); - - $this->sql = "DELETE FROM ".$table." WHERE ".$wh.";"; - $this->query = $this->connetction->prepare($this->sql); - $this->rt = $this->query->execute(); - if ($this->rt) { - return $this->rt; - - } - } - - - - -} - - - - +connetction = $connetction; +} + +public function Select_ch($table,$data = array()) +{ + array_keys($data); + $qt = ""; + foreach(array_merge($data) as $item){ + $qt .= $item.", "; + } + $res = rtrim($qt,", "); + + $this->sql = "Select ".$res." from ".$table; + $this->query = $this->connetction->prepare($this->sql); + $this->query->execute(); + + while($this->rt = $this->query->fetchAll()) { + return $this->rt; + }; + // TODO: Implement Select_ch() method. +} + +public function Select_all($table) + { + $this->sql = "Select * from ".$table; + $this->query = $this->connetction->prepare($this->sql); + $this->query->execute(); + + while($this->rt = $this->query->fetchAll()) { + return $this->rt; + }; + + + } + + public function Select_wh($table,$data = array(),$con = array(),$if = array()){ + + + $q = ""; + $i = 0; + $b = 1; + foreach($data as $x => $val) { + $q .= " $x ".$con[$i]." $val ".$if[$b - 1]; + $i++; + } + + $res = rtrim($q,"AND"); + + + $this->sql = "SELECT * FROM ".$table." WHERE ". $res; + + $this->query = $this->connetction->prepare($this->sql); + $this->query->execute(); + + while($this->rt = $this->query->fetchAll()) { + return $this->rt; + }; + + + + } + +public function Insert($table, $data = array()) +{ + $quote = ""; + foreach (array_keys($data) as $item){ + $quote .= $item." = :". "$item, "; + } + $res = rtrim($quote,", "); + + $this->sql = "INSERT INTO ".$table." SET " . $res; + $this->query = $this->connetction->prepare($this->sql); + $this->rt = $this->query->execute($data); + if ($this->rt) { + //return $this->connection->lastInsertId(); + return $this->rt; + } + + + // TODO: Implement Insert() method. +} + +public function Update($table, $id = array(), $data = array()) + { + + $quete = ""; + + foreach($data as $x => $val) { + $quete .= "$x = '$val', "; + } + + $res = rtrim($quete,", "); + + $wher = ""; + + foreach($id as $x => $val) { + $wher .= "$x = $val, "; + } + + $wh = rtrim($wher,", "); + + + $this->sql = "UPDATE ".$table." SET " . $res . " WHERE ".$wh.";"; + + $this->query = $this->connetction->prepare($this->sql); + + $this->rt = $this->query->execute(); + if ($this->rt) { + return $this->rt; + + } + + } + + public function Delete($table, $id = array()) + { + + $wher = ""; + + foreach($id as $x => $val) { + $wher .= "$x = $val, "; + } + + $wh = rtrim($wher,", "); + + $this->sql = "DELETE FROM ".$table." WHERE ".$wh.";"; + $this->query = $this->connetction->prepare($this->sql); + $this->rt = $this->query->execute(); + if ($this->rt) { + return $this->rt; + + } + } + + + + +} + + + + ?> \ No newline at end of file diff --git a/src/qwerty/Config/SqlPattern.php b/src/Config/SqlPattern.php similarity index 91% rename from src/qwerty/Config/SqlPattern.php rename to src/Config/SqlPattern.php index 22baf96..7e6c62e 100644 --- a/src/qwerty/Config/SqlPattern.php +++ b/src/Config/SqlPattern.php @@ -1,14 +1,14 @@ -DBHost; + } + + function showDBName() + { + return $this->DBName; + } + + function showDBUser() + { + return $this->DBUser; + } + + function showDBPassword() + { + return $this->DBPassword; + } + + function showConnection() + { + return $this->Connection; + } + + + + /* + + const DBHost = "localhost"; + const DBHost = "localhost"; + const DBHost = "localhost"; + const DBHost = "localhost"; + const DBHost = "localhost"; + + define("localhost","localhost"); +define("dbname","sifirdanphp"); +define("dbuser","postgres"); +define("dbpass","489623sunA"); +define("connection1","connection"); + +define("DBHost","localhost"); +define("DBName","northwind"); +define("DBUser","root"); +define("DBPassword",""); +define("connection","connection"); +*/ + + + +} + +?> \ No newline at end of file diff --git a/src/qwerty/Database/Database.php b/src/Database/Database.php similarity index 55% rename from src/qwerty/Database/Database.php rename to src/Database/Database.php index 98ac642..e89a6e1 100644 --- a/src/qwerty/Database/Database.php +++ b/src/Database/Database.php @@ -1,46 +1,41 @@ -dbhost = $dbhost; - $this->dbname = $dbname; - $this->dbuser = $dbuser; - $this->dbpass = $dbpass; - $this->connection = $connection; - - } - - - public function MysqlConnection(){ - $this->connection = new PDO("mysql:host=".$this->dbhost.";dbname=".$this->dbname.";charset=utf8", $this->dbuser, $this->dbpass); - return $this->connection; - //echo "accept"; - } - - public function PostgresqlConnection(){ - $this->connection = new PDO("pgsql:host=".$this->dbhost.";port=5432;dbname=".$this->dbname.";",$this->dbuser,$this->dbpass); - //echo "accept"; - return $this->connection; - - } - - - -} - - - -?> - +dbhost = $dbhost; + $this->dbname = $dbname; + $this->dbuser = $dbuser; + $this->dbpass = $dbpass; + $this->connection = $connection; + + } + + + public function MysqlConnection(){ + $this->connection = new PDO("mysql:host=".$this->dbhost.";dbname=".$this->dbname.";charset=utf8", $this->dbuser, $this->dbpass); + return $this->connection; + } + + public function PostgresqlConnection(){ + $this->connection = new PDO("pgsql:host=".$this->dbhost.";port=5432;dbname=".$this->dbname.";",$this->dbuser,$this->dbpass); + return $this->connection; + } + +} + + + +?> + diff --git a/src/qwerty/Database/DatabaseController.php b/src/Database/DatabaseController.php similarity index 57% rename from src/qwerty/Database/DatabaseController.php rename to src/Database/DatabaseController.php index 794335e..ee98a61 100644 --- a/src/qwerty/Database/DatabaseController.php +++ b/src/Database/DatabaseController.php @@ -1,40 +1,20 @@ - \ No newline at end of file diff --git a/src/qwerty/Database/DatabaseFace.php b/src/Database/DatabaseFace.php similarity index 81% rename from src/qwerty/Database/DatabaseFace.php rename to src/Database/DatabaseFace.php index 406d782..1a557f1 100644 --- a/src/qwerty/Database/DatabaseFace.php +++ b/src/Database/DatabaseFace.php @@ -1,12 +1,13 @@ - \ No newline at end of file diff --git a/src/Ext.php b/src/Ext.php deleted file mode 100644 index 0fa720b..0000000 --- a/src/Ext.php +++ /dev/null @@ -1,58 +0,0 @@ -MysqlConnection(); -//$baglanti = $db->PostgresqlConnection(); - -$method = new Method($cn); - -//$veri = $method->Select_all("orders"); -/* - -$data = array( - 'ShipName' => "deneme", - 'ShipAddress' => "deneme", - 'ShipCity' => "deneme" -); -*/ -//$method = $method->Insert("orders",$data); - -$id = array( - 'OrderID',"CustomerID" -); - -/* -$data = array( - 'ShipName' => "12", - 'ShipAddress' => "12", - 'ShipCity' => "12" -); - - -$method = $method->Update('orders', $id, $data); -*/ - -//$method = $method->Delete('orders',$id); - -$data = array( - "EmployeeID" => "4" -); -$con = array("!="); -$if = array("AND"); - -//$a = $method->Select_ch("orders",$id); - -$a = $method->Select_wh('orders',$data,$con,$if); - -print_r($a); - - -?> \ No newline at end of file diff --git a/src/autoload.php b/src/autoload.php deleted file mode 100644 index d85a06d..0000000 --- a/src/autoload.php +++ /dev/null @@ -1,9 +0,0 @@ - \ No newline at end of file diff --git a/src/constants.php b/src/constants.php deleted file mode 100644 index 61138f1..0000000 --- a/src/constants.php +++ /dev/null @@ -1,32 +0,0 @@ - \ No newline at end of file diff --git a/tests/ConnectionTest.php b/tests/ConnectionTest.php new file mode 100644 index 0000000..7ada6f1 --- /dev/null +++ b/tests/ConnectionTest.php @@ -0,0 +1,10 @@ + + \ No newline at end of file