Библиотека для cis, online, cms1
This commit is contained in:
commit
3c2e614d87
269 changed files with 39854 additions and 0 deletions
50
core/drivers/db.php
Normal file
50
core/drivers/db.php
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* Èíòåðôåéñ äðàéâåðà êëàññà áàç äàííûõ
|
||||
*/
|
||||
interface IDatabase
|
||||
{
|
||||
public function connect(array $dsn);
|
||||
public function close();
|
||||
public function query($query);
|
||||
public function fetchAllArray($query);
|
||||
public function fetchOneArray($query);
|
||||
}
|
||||
|
||||
abstract class DB implements IDatabase
|
||||
{
|
||||
const limit = 1024;
|
||||
protected $db;
|
||||
|
||||
public static function quote($x)
|
||||
{
|
||||
return "'" . $x . "'";
|
||||
}
|
||||
|
||||
private static function assign_quote($x, $y)
|
||||
{
|
||||
return $x . "='" . $y . "'";
|
||||
}
|
||||
|
||||
function insert($table, array $values)
|
||||
{
|
||||
return $this->query("INSERT INTO $table (" . implode(",", array_keys($values))
|
||||
. ") VALUES (" . implode(",", array_map(array('self', 'quote'), array_values($values))) . ")");
|
||||
}
|
||||
|
||||
function update($table, array $values, $cond)
|
||||
{
|
||||
return $this->query("UPDATE $table SET " . implode(",",
|
||||
array_map(array('self', 'assign_quote'), array_keys($values), array_values($values))) . " WHERE $cond");
|
||||
}
|
||||
|
||||
function check_text($text)
|
||||
{
|
||||
if(strlen($text) > self::limit) $text = substr($text, 0, self::limit);
|
||||
$text = htmlspecialchars(trim($text));
|
||||
return $text;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
Loading…
Add table
Add a link
Reference in a new issue