Skip to content
Snippets Groups Projects
datenbank.inc.php 2.79 KiB
Newer Older
<?php
  require_once( __DIR__ .'/db_config.php');
isaack's avatar
isaack committed
	//Passwort zusatz
	$pw_zusatz = 'fg65en';
isaack's avatar
isaack committed
	
	// Verschlüsselungspasswort
	$ver_schluessel = 'libh5476H6G4v0TB';
isaack's avatar
isaack committed
	
Eric Laufer's avatar
Eric Laufer committed
	//Datenbankverbindung herstellen
	$sql_open = @mysqli_connect( DB_HOST, DB_USER, DB_PASS, DB_BASE ) or die('Verbindung zum Mysql Server fehlgeschlagen! <br>Tipp: <a href="http://www.vms-tutorial.de/wiki//Lib/Functions">http://www.vms-tutorial.de/wiki//Lib/Functions</a>');
  // why?:
	$sql_base = @mysqli_select_db($sql_open, DB_BASE ) or die("Keine oder falsche Datenbank gewhlt! Tipp: <br><a href='http://www.vms-tutorial.de/wiki//Lib/Functions'>http://www.vms-tutorial.de/wiki//Lib/Functions</a>");

Eric Laufer's avatar
Eric Laufer committed
	/**
	 * db_connect()
	 *
	 * @author designerscripte.net
	 * @category system Database
	 * @version 2.5.0
	 * @example db_query("SELECT `field` FROM `table` WHERE `field` = `value` ");
	 * @param mixed $sql_tag
	 * @return 0 bei Fehler Mysql_resource.
	 *
	 */
	function db_query($sql_tag) {
		global $count_query,$sql_open;
		$count_query++;
		$fargs = func_get_args();

		if (!empty($fargs)) {
			$vargs = array();
			foreach($fargs as $key => $arg) {
				$vargs[$key] = mysqli_real_escape_string($sql_open,$arg);
			}
			array_shift($vargs);
			if (!empty($vargs))$sql_tag = vsprintf($sql_tag, $vargs);
		}
		if ($ret = mysqli_query($sql_open,$sql_tag)) {
			return $ret;
		}else {
			return 0;
		}
isaack's avatar
isaack committed
		

/*
* taken from  nieprzeklinaj at gmail dot com
* http://php.net/manual/de/mysqli-stmt.bind-result.php
*/
function db_fetch($result)
{   
    $array = array();
   
    if($result instanceof mysqli_stmt)
    {
        $result->store_result();
       
        $variables = array();
        $data = array();
        $meta = $result->result_metadata();
       
        while($field = $meta->fetch_field())
            $variables[] = &$data[$field->name]; // pass by reference
       
        call_user_func_array(array($result, 'bind_result'), $variables);
       
        $i=0;
        while($result->fetch())
        {
            $array[$i] = array();
            foreach($data as $k=>$v)
                $array[$i][$k] = $v;
            $i++;
           
            // don't know why, but when I tried $array[] = $data, I got the same one result in all rows
        }
    }
    elseif($result instanceof mysqli_result)
    {
        while($row = $result->fetch_assoc())
            $array[] = $row;
    }
   
    return $array;
}
isaack's avatar
isaack committed
	function pw_erstellen($pw){
		global $pw_zusatz;
		$pw_er = hash("sha256",$pw.$pw_zusatz);
		return $pw_er;
	}
	
Eric Laufer's avatar
Eric Laufer committed
	/**
	 * db_close()
	 *
	 * @author designerscripte.net
	 * @category system Database
	 * @version 2.5.0
	 * @example db_close();
	 * @return die(''); bei fehler nichts bei erfolg
	 */
	function db_close() {
		global $sql_open;
		@mysqli_close($sql_open) or die('Konnte die Verbindung mit Datenbank nicht schliessen!');
	}
	?>
isaack's avatar
isaack committed