Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class libSQL
- {
- private $_sql_link;
- private $_sql_query;
- private $_sql_params;
- private $_sql_retval;
- public function connect($host, $user, $pass)
- {
- $this->_sql_link = @mysql_connect($host, $user, $pass, true);
- if(!$this->_sql_link)
- {
- $this->sendError('Cant connect to the MySQL Server.');
- }
- }
- public function database($db)
- {
- if(!mysql_select_db($db))
- {
- $this->sendError('Cant connect to the Database.');
- }
- }
- public function query($string)
- {
- $this->_sql_query = $string;
- }
- public function bind($name, $value)
- {
- $this->_sql_params[$name] = $value;
- }
- public function protect()
- {
- foreach($this->_sql_params as $name => $value)
- {
- $this->_sql_params[$name] = mysql_real_escape_string($value, $this->_sql_link);
- }
- }
- public function execute()
- {
- foreach($this->_sql_params as $name => $value)
- {
- $this->_sql_query = str_replace("{!$name}", $value, $this->_sql_query);
- }
- $this->_sql_params = array();
- $this->_sql_retval = @mysql_query($this->_sql_query, $this->_sql_link);
- if(!$this->_sql_retval)
- {
- $this->sendError('Cant execute the Query.');
- }
- }
- public function result()
- {
- return mysql_fetch_object($this->_sql_retval);
- }
- public function disconnect()
- {
- mysql_close($this->_sql_link);
- }
- private function sendError($msg)
- {
- die($msg);
- }
- }
- $sql = new libSQL();
- $sql->connect("localhost", "root", "");
- $sql->database("phpmyadmin");
- $sql->query("SELECT * FROM {!db} WHERE username = '{!name}' LIMIT 1;");
- $sql->bind('db', 'pma_history');
- $sql->bind('name', 'root');
- $sql->protect();
- $sql->execute();
- // while($var = $sql->result()) ghet auch
- echo $sql->result()->username;
- $sql->disconnect();
- ?>
Add Comment
Please, Sign In to add comment