Zrobiłem wszystko, doszedłem... Tylko czy dobrze wywołuje tą funkcje w innych funkcjach? hehe:
<?php
/*
* MySQL CLASS
*
* @author Tomasz K. <xxdrago at gmail dot com>
* @copyright 2013
* @version 1.0
*/
public function Connect($mysql_host, $database, $port, $kodowanie, $username, $password) {
# --------------------------------
// Use
// $MySQL->Connect('localhost', 'datbase', 'encoding', 'port', 'username', 'password');
# --------------------------------
$port = '3306';
}
$kodowanie = 'utf8';
}
$pdo = new PDO('mysql:host=' . $mysql_host . ';dbname=' . $database . ';encoding=' . $kodowanie . ';port=' . $port, $username, $password);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->Connect = $pdo;
}
private function BindValue($data, $stmt) {
foreach ($data as $nazwa => $wartosc) {
$stmt->bindValue(':' . $nazwa, $wartosc, PDO::PARAM_STR);
}
return $stmt;
}
private function Where($data) {
$where = 'WHERE ';
foreach ($data as $nazwa => $wartosc) {
if ($nazwa != $ostatni) {
$where.='' . $nazwa . '= :_' . $nazwa . ' ';
} else {
$where.='AND ' . $nazwa . '= :_' . $nazwa . '';
}
} else {
$where.='' . $nazwa . '= :_' . $nazwa . ' ';
}
}
return $where;
}
public function insert($tabela, $data) {
# --------------------------------
// Use
// $MySQL->insert('tabela', $data);
// $data = array
// $data = array('nazwa' => 'test','wartosc' => 'wartosc');
# --------------------------------
foreach ($data as $nazwa => $wartosc) {
$datas[':' . $nazwa] = $wartosc;
}
$stmt = $this->Connect->prepare('INSERT INTO ' . $tabela . ' (' . $klucze . ') VALUES(' . $nazwa2 . ')');
self::BindValue($data, $stmt);
$stmt->execute();
$stmt->closeCursor();
}
public function update($tabela, $data, $where) {
# --------------------------------
// Use
// $MySQL->update($tabela, $data, $where);
// $data = array
// $where = array MAX 2
# --------------------------------
foreach ($data as $nazwa => $wartosc) {
$datas[':' . $nazwa] = $wartosc;
}
foreach ($where as $nazwa => $wartosc) {
$wheree[0] = $nazwa;
$wheree[1] = $wartosc;
}
foreach ($where as $nazwa => $wartosc) {
$data2['_' . $nazwa] = $wartosc;
}
$wartosci = 'UPDATE ' . $tabela . ' SET ';
foreach ($data as $nazwa => $wartosc) {
if ($nazwa != $ostatni) {
$wartosci.= $nazwa . '=' . ':' . $nazwa . ', ';
} else {
$wartosci.= $nazwa . '=' . ':' . $nazwa;
}
}
$wartosci.= ' ' . self::Where($where) . ' LIMIT 1;';
$stmt = $this->Connect->prepare($wartosci);
self::BindValue($data, $stmt);
self::BindValue($data2, $stmt);
$stmt->execute();
$stmt->closeCursor();
}
public function delate($tabela, $where) {
# --------------------------------
// Use
// $MySQL->delate($tabela, $where);
// $tabela = ;
// $where = array MAX 2
# --------------------------------
$zapytanie = 'DELETE FROM ' . $tabela . ' ' . self::Where($where);
foreach ($where as $nazwa => $wartosc) {
$data['_' . $nazwa] = $wartosc;
}
$stmt = $this->Connect->prepare($zapytanie);
self::BindValue($data, $stmt);
$stmt->execute();
$stmt->closeCursor();
}
public function select($tabela, $order, $where, $limit) {
$orderr = '';
} else {
foreach ($order as $nazwa => $wartosc) {
$order[0] = $nazwa;
$order[1] = $wartosc;
}
$orderr = ' ORDER BY ' . $order[0] . ' ' . $order[1];
}
// SELECT *
//FROM `config`
//ORDER BY `wartosc` ASC
//LIMIT 0 , 30
// $select = 'SELECT * FROM' . $tabela . $orderr . ' LIMIT 0, ' . $limit;
//$stmt = $this->Connect->prepare($zapytanie);
// self::BindValue($data, $stmt);
}
}
?>
Znalazłem to
self::BindValue($data, $stmt); , gdzieś w innej klasie... chciałem więcej poczytać o OOP ale za cholere nic nie idzie znaleźć na internecie, wcześniej chodziło mi o to, że nie wiedziałem jak wywołać tą funkcje... Takie pytanie w dobrym kierunku idę?