Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class mysqliControl {
- private $dbhost;
- private $dbuser;
- private $dbpass;
- private $dbname;
- private $connected;
- private $errorfeedb
- function __construct( $host, $user, $pass, $name, $errorfeedback=false ) {
- $this->dbhost = $host;
- $this->dbuser = $user;
- $this->dbpass = $pass;
- $this->dbname = $name;
- $this->dblink = new MySQLi( $this->dbhost, $this->dbuser,
- $this->dbpass, $this->dbname );
- $this->connected = true;
- $this->errorfeedback = $errorfeedback;
- }
- function query( $query ) {
- $qresult = mysqli_query( $this->dblink, $query );
- if( $this->errorfeedback ) {
- if( $qresult != false ) {
- return $qresult;
- } else {
- print "ERROR IN '" . $query . "'<br/>";
- }
- } else {
- return $qresult;
- }
- }
- function cleaninput( $input ) {
- $out = str_replace(array('\\', "\0", "\n", "\r", "'", '"', "\x1a"), array('\\\\', '\\0', '\\n', '\\r', "\\'", '\\"', '\\Z'), $input);
- $removalwords = array("/delete/i", "/update/i","/union/i","/insert/i","/drop/i","/http/i","/--/i");
- $out = preg_replace($removalwords, "", $out);
- return $out;
- }
- function maketable( $tablename, $values) {
- $tablequery = "CREATE TABLE IF NOT EXISTS ";
- $tablequery = $tablequery . $this->cleaninput( $tablename ) . " (" . $values . ")";
- $this->query( $tablequery );
- }
- function updatevalue( $tablename, $column1, $value1, $column2, $create=true ) {
- $querystring = "SELECT * FROM " . $this->cleaninput( $tablename ) . " WHERE " . $this->cleaninput( $column1 ) . " = '" . $this->cleaninput( $value1 ) . "'";
- $result = $this->query( $querystring );
- if( $result->num_rows ) {
- $querystring = "UPDATE " . $this->cleaninput( $tablename ) . " SET " . $this->cleaninput( $column2 ) . " = " . $this->cleaninput( $column2 ) . " + 1 WHERE " . $this->cleaninput( $column1 ) . " = '" . $this->cleaninput( $value1 ) . "'";
- $this->query( $querystring );
- } else {
- $querystring = "INSERT INTO " . $this->cleaninput( $tablename ) . " (" . $this->cleaninput( $column1 ) . ", " . $this->cleaninput( $column2 ) . ") VALUES ('" . $this->cleaninput( $value1 ) . "', '1')";
- $this->query( $querystring );
- }
- }
- function select( $table, $column ) {
- $selectquery = "SELECT " . $column . " FROM " . $table;
- $result = $this->query( $selectquery );
- $numrows = $result->num_rows;
- $content = array();
- for( $i = 1; $i <= $numrows; $i++ ) {
- $currentline = $result->fetch_row();
- $content[$i] = $currentline;
- }
- return $content;
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement