Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- ** Please define SQL_*
- */
- class Sql
- {
- private $_SQL;
- public function __construct($user = SQL_USR, $password =
- SQL_PSSWD, $database = SQL_DB, $host = SQL_HOST)
- {
- try
- {
- $this->_SQL = new PDO('mysql:host='
- .$host. ';dbname=' .$database, $user, $password);
- }
- catch(Exception $e)
- {
- echo($e->getMessage());
- }
- }
- public function __destruct()
- {
- }
- public static function PrefixQuery($str)
- {
- $words = array("INNER", "LEFT", "RIGHT", "JOIN",
- "ON");
- $i = -1;
- $flag = 0;
- $tmp = "";
- if (SQL_PREFIXE == "")
- return ($str);
- $str = str_replace(',', ', ', $str);
- $rray = explode(' ', $str);
- $size = count($rray);
- while (++$i < $size)
- {
- while ($rray[$i] == "")
- ++$i;
- if ($rray[$i] == "WHERE")
- $flag = 2;
- if ($i != 0)
- $tmp .= ' ';
- if ($flag == 1 && !in_array($rray[$i],
- $words))
- $tmp .= SQL_PREFIXE.$rray[$i];
- else
- {
- if
- (preg_match('/^[A-Za-z0-9_-]+\.{1}[A-Za-z0-9_-]+$/', $rray[$i]))
- $tmp .=
- SQL_PREFIXE.$rray[$i];
- else
- $tmp .= $rray[$i];
- }
- if ($rray[$i] == "FROM")
- $flag = 1;
- }
- return ($tmp);
- }
- public function Query($q)
- {
- $query = $this->_SQL->query($q);
- return ($query);
- }
- public function Execute($query, $data = NULL)
- {
- $qry = $this->_SQL->prepare($query);
- if ($data == NULL)
- return ($qry->execute());
- return ($qry->execute($data));
- }
- public function ExecuteAll($query, $data = NULL)
- {
- $qry = $this->_SQL->prepare($query);
- if ($data != NULL)
- {
- if (!$qry->execute($data))
- return (false);
- }
- else
- $qry->execute();
- $r = $qry->fetchAll();
- return ($r);
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement