File: /var/www/web37/htdocs/top100-sexnetzwerk/inc/sql.php
<?php
if ($scriptpath!=$_SERVER['DOCUMENT_ROOT'])
{echo "Are you looking for something?";exit;}
/// Sql connect data
$mysql_host = 'localhost'; // hostname of the sql server
$mysql_username = 'web37'; // mysql-username
$mysql_passwd = 'pinkostar'; // mysql-password
$mysql_dbase = 'usr_web37_9'; // the name of the database
$dbtbpre = "topxl"; /// Vorspann für den tabellen namen, bei mehreren Toplisten in einer tabelle
/// Tables - only make changes behind this line if you know what you are doing
$topxl_user_table = $dbtbpre."_user";
$topxl_admin_table = $dbtbpre."_admin";
$topxl_hits_table = $dbtbpre."_hits";
$topxl_promotial_table = $dbtbpre."_promotial";
$topxl_stats1_table = $dbtbpre."_stats1";
/// dont change anything behind this line!!!!! Ab hier nichts mehr ändern!!!!!!!
$mysqli_config = array (
'MYSQL_HOST' => $mysql_host,
'MYSQL_USER' => $mysql_username,
'MYSQL_PASS' => $mysql_passwd,
'MYSQL_DB' => $mysql_dbase,
'MYSQL_CHARSET' => 'utf8',
'MYSQL_SHOWERROR' => empty ($mysql_showerror) ? false : $mysql_showerror
);
$db = new db ($mysqli_config);
$db -> connect ();
/**
* class db mysqli db class
*
*/
class db
{
/**
* @var object $result the reuslt of a query
*/
protected $result = 0;
/**
* @var object $stmt
*/
protected $stmt = 0;
/**
* @var int $errno the error code for the most recent function call
*/
protected $errno = 0;
/**
* @var string $sqlQuery the sql query (e.g. select * from x...)
*/
public $sqlQuery;
/**
* @var object mySqli
*/
public $mySqli;
/**
* @var array $c the configuration
*/
public $c;
/**
* @var string $error true/false / shall sql errors been shown?
*/
public $error;
/**
* @method null __construct(array $c) inject container
*/
public function __construct ($c)
{$this -> c = $c;}
/**
* @method null connect() invokes the connectDb method automatically and the connectError method and charset methiod (if specified in $this -> c['config'] -> MYSQL_CHARSET)
*/
public function connect ()
{
$this -> connectDb ();
$this -> connectError ();
(!empty ($this -> c['MYSQL_CHARSET'])) ? $this -> charset () : '';
}
/**
* @method null connectDb() connect to databse
*/
protected function connectDb ()
{$this -> mySqli = new mysqli ($this -> c['MYSQL_HOST'], $this -> c['MYSQL_USER'], $this -> c['MYSQL_PASS'], $this -> c['MYSQL_DB']);}
/**
* @method null charset() set mysql connection charset
*/
protected function charset ()
{$this -> mySqli -> set_charset ($this -> c['MYSQL_CHARSET']);}
/**
* @method null connectError() get mysql connection errors
*/
protected function connectError ()
{
if (!empty ($this -> c['MYSQL_SHOWERROR']) && $this -> mySqli -> connect_errno)
{echo "<strong>" . $this -> mySqli -> connect_errno.": ". $this -> mySqli -> connect_error ." </strong><br />";}
}
/**
* @method null query(string $sqlQuery) execute mysql query
*/
public function query ($sqlQuery)
{
$this -> sqlQuery = trim ($sqlQuery);
# query in der Klasse speichern
$this -> result = $this -> mySqli -> query ($this -> sqlQuery);
# wenn die Abfrage kein Ergebniss ergab -> fehler!
if (!$this -> result)
{
$this -> errno = $this -> mySqli -> errno;
$this -> error = $this -> mySqli -> error;
# fehler ausgeben
($this -> c['MYSQL_SHOWERROR'] == true) ? $this -> getError () : '';
}
}
/**
* @method null getError() output errors (from query method)
*/
protected function getError ()
{
if ($this -> error)
{
$str = "Anfrage:\n".$this -> sqlQuery."\n<br />";
$str .= "Antwort:\n".$this -> error."\n<br />";
$str .= "Fehlercode: ".$this -> errno."\n<br />";
echo $str;
}
return false;
}
/**
* @method object/null fetch() fetch query method result assoc f.e. while ($row = $this -> fetch ()) { ...
*/
public function fetch ()
{
if ($this -> error)
{return null;}
else
{return $this -> result -> fetch_assoc ();}
}
/**
* @method object/null serverInfo()
*/
public function serverInfo ()
{return $this -> mySqli -> server_info;}
/**
* @method int/null numRows() get number of result rows
*/
public function numRows ()
{
if ($this -> error)
{$return = -1;}
else
{$return = $this -> result -> num_rows;}
return $return;
}
/**
* @method int insertId() get the last inserted primary key
*/
public function insertId ()
{
if ($this -> error)
{return -1;}
else
{return $this -> mySqli -> insert_id;}
}
/**
* @method null free() free mysql result
*/
public function free ()
{$this -> result -> free ();}
/**
* @method string escape() escape vars
*/
public function escape ($string)
{return $this -> mySqli -> real_escape_string (stripslashes ($string));}
}
?>