Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/stnc/pdo-database
a PDO database service provider for mysql
https://github.com/stnc/pdo-database
composer metod mysql pdo pdo-database php
Last synced: 3 days ago
JSON representation
a PDO database service provider for mysql
- Host: GitHub
- URL: https://github.com/stnc/pdo-database
- Owner: stnc
- Created: 2015-08-06T19:18:49.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2021-05-21T12:14:25.000Z (over 3 years ago)
- Last Synced: 2024-11-09T09:16:17.767Z (about 2 months ago)
- Topics: composer, metod, mysql, pdo, pdo-database, php
- Language: PHP
- Size: 56.6 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# pdo-database
easy ,basic ,simple mysql provider
A super simple function that returns the full SQL query from your PDO statements
a PDO database service provider for mysql and portgreSQL# Composer install
composer require stnc/pdo-database## 1. Installing-Connections
```php
require_once 'vendor/autoload.php';
define('DB_TYPE', 'mysql');
define('DB_HOST', 'localhost');
define('DB_NAME', 'wordpress');
define('DB_USER', 'root');
define('DB_PASS', '');
```
## 2. Connections
```php
/* //use 1
use Stnc\Db\MysqlAdapter ;
$db = new MysqlAdapter();
*//* //use 2
use Stnc\Db\MysqlAdapter as dbs;
$db = new dbs();
*///use 3
$db = new Stnc\Db\MysqlAdapter();
$tableName = 'users';
```
## 3. Select multiple rows
```php
$q = "SELECT * FROM ".$tableName;
$array_expression = $db->fetchAll ( $q );
foreach ( $array_expression as $value ) {
echo $value ['name'];
echo '
';
}
```
## 4. Select single row
```php
$tableName = 'wp_options';//wordpress
$q = "SELECT * FROM ".$tableName;
$array_expression = $db->fetch ( $q );
echo $array_expression ['name'];
//or
$q = 'SELECT * FROM '.$tableName.' where option_name="siteurl" ';
$array_expression = $db->fetch ( $q );
print_r ($array_expression);
echo $array_expression ['option_name'];```
## 5. Query
```php
$q = "ALTER TABLE users MODIFY COLUMN user_id int(11) NOT NULL AUTO_INCREMENT FIRST";
$db->query ( $q );
```
## 6. insert data
```php
$data = array (
'name' => "john",
'lastname' => "carter",
'status' => 1,
'age' => 25
);$db->insert ( $tableName, $data );
```
## 7. update metod
```php
$data = array (
'name' => "john",
'lastname' => "carter",
'status' => 1,
'age' => 25
);
$where = array (
'user_id' => 1
);
$db-> update ( $tableName, $data, $where );
```
## 8. Delete metod
```php
$where = array (
'user_id' => 1
);return $db->delete ( $tableName, $where );
```## 9. last id
```php
$db->lastID();
```## 10. Orm Mass Updates
```php
$db->tableName=$tableName;
$db->where('id', '=', 1)->update2(['username' =>'selman sedat']);
```