Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/n2ref/database
The class to use a database
https://github.com/n2ref/database
Last synced: 7 days ago
JSON representation
The class to use a database
- Host: GitHub
- URL: https://github.com/n2ref/database
- Owner: n2ref
- License: mit
- Created: 2013-08-12T21:41:30.000Z (over 11 years ago)
- Default Branch: master
- Last Pushed: 2014-01-07T18:40:19.000Z (almost 11 years ago)
- Last Synced: 2023-09-29T14:18:50.237Z (about 1 year ago)
- Language: PHP
- Size: 164 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
DataBase
========Class for using the database, with the ability to use different adapters such as 'Mysqli', 'PostgreSQL', 'Mssql' and some other
Simple example, initialize and select
```php
require_once 'class.database.php';
$db = new DB('PDO_Mysql', 'localhost', 'workbase', 'user_name', 'user_pass');$result_array = $db->fetchRow("
SELECT title,
description,
data
FROM table_name
WHERE id = ?
", $id);// also exists methods fetchAll, fetchOne
```Slightly more complex example of using a method 'query'
```php
$db = new DB('PDO_Mysql', 'localhost', 'workbase', 'user_name', 'user_pass');// here is screened and paste parameters in the query
$is_add = $db->query("
INSERT INTO table_items (
title,
preview,
content,
category_id,
user_id,
published,
last_modified
) VALUE (
:title,
:preview,
:content,
:category_id,
:user_id,
'1',
NOW()
)
", array(
'title' => $item['title'],
'preview' => $item['preview'],
'content' => $item['content'],
'category_id' => $item['category_id'],
'user_id' => $item['user_id']
)
);if ($is_add) {
$item_id = $db->lastInsertId();
}$db->close();
```