Skip to content
Snippets Groups Projects
datenbank.inc.php 3.21 KiB
Newer Older

require_once( __DIR__ .'/db_config.php' );
require_once( __DIR__ .'/../class/database.php' );
isaack's avatar
isaack 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>");

// please use global $database, $GLOBALs['database'] or pass $database to class/function
// avoid cluttering the code with silly singleton calls, except when really needed,
// for example when connectiong to a different database, thank you
$database = Database::get(
                array(
                    'type' => 'mysql',
                    'host' => DB_HOST,
                    'name' => DB_BASE,
                    'user' => DB_USER,
                    'pass' => DB_PASS,
                )
            );
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){
		$pw_er = hash("sha256",$pw. PW_ZUSATZ );
isaack's avatar
isaack committed
		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!');
	}
Christoph Zysik's avatar
Christoph Zysik committed
?>