Newer
Older
<?php
require_once( __DIR__ .'/db_config.php');
$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>");
/**
* 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;
}
Christoph Zysik
committed
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
* 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;
}
function pw_erstellen($pw){
global $pw_zusatz;
$pw_er = hash("sha256",$pw.$pw_zusatz);
return $pw_er;
}
/**
* 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!');
}
?>