0) {
if (!$offset || $offset < 0) {
$offset=0;
}
$qstring=$qstring." LIMIT $offset,$limit";
}
// if ($GLOBALS['IS_DEBUG'])
$GLOBALS['G_DEBUGQUERY'] .= $qstring . "
\n";
//
//are we configured to try to use replication?
//
if ($sys_db_use_replication) {
//
//if we haven't yet done an insert/update,
//read from the read-only db
//
if (!$sys_db_is_dirty && mb_eregi("^( )*(select)",$qstring)) {
if ($QUERY_COUNT%3==0) {
// 1/3rd of read queries go to master for now
return mysqli_query($sys_dbname,$qstring,$conn_update);
} else {
return mysqli_query($sys_dbname,$qstring,$conn);
}
} else {
//must be an update/insert/delete query - go to master server
$sys_db_is_dirty=true;
return mysqli_query($sys_dbname,$qstring,$conn_update);
}
} else {
$ret = mysqli_query($conn, $qstring);
// echo "@mysql_db_query($sys_dbname,$qstring,$conn); ret=$ret
";
if(!$ret){
$e = new mb_exception("db_query($qstring)=$ret db_error=".db_error());
}
return $ret;
}
//echo "SQL__".$qstring;
}
function db_prepare_typestr($types) {
$result = '';
foreach ($types as $current_type) {
$result .= $current_type;
}
return $result;
}
/**
* prepare and query the database
*
* @param $qstring (string) SQL statement
* @param $params (array string params)
* @param $types (array string types)
*/
function db_prep_query($qstring, $params, $types){
$orig_qstring = $qstring;
// Beim Umschreiben an der PostGreSQL-Bibliothek orientieren
global $conn, $stmt;
@mysqli_stmt_close($stmt);
$ci = new checkInput($qstring,$params,$types);
$params = $ci->v;
if(PREPAREDSTATEMENTS == false){
for ($i=0; $i 0) {
$param_string .= ', ';
$val_string .= ', ';
}
$param_string .= '"'.$params[$i].'"';
if ($types[$i] == 's')
$val_def_string .= '$val'.$i.'="'.$params[$i].'";';
else
$val_def_string .= '$val'.$i.'='.$params[$i].';';
$val_string .= '$val'.$i;
//mysqli_stmt_bind_param($result, $types[$i], $params[$i]);
}
}*/
for( $i = 0; $i < count($params); ++$i ) {
$thisVar = "v$i";
$variadicParams .= '$' . $thisVar;
if( $i != count($params) - 1 ) // don't append a comma on the last variable
$variadicParams .= ', ';
$variadicExtVars[ $thisVar ] = $params[ $i ];
}
echo $variadicParams;
$bindParamFunc = create_function( '$vars, &$stmt','extract( $vars ); $stmt->bind_param( \'' . implode($types) . '\', ' . $variadicParams . ' );' );
$bindParamFunc( $variadicExtVars, $stmt );
/* $typeStr = call_user_func_array( 'db_prepare_typestr', $types );
array_unshift( $params, $typeStr );
call_user_func_array( array( 'mysqli_bind_param', $qstring ), $params ); */
/*$type_string .= '"';
$eval_string = $val_def_string.'mysqli_stmt_bind_param($result,'.$type_string.','.$val_string.');';
$xyz=1;
//$eval_string = 'eead results, this function cancelcho $result;';
//$eval_string = 'return mysqli_stmt_bind_param($result,'.$type_string.',$xyz);';
echo $eval_string;
//echo "mysqli_stmt_bind_param($result,$type_string,$param_string)";
eval($eval_string);*/
$r = mysqli_stmt_execute($stmt);
if(!$r){
$e = new mb_exception("Error while executing prepared statement in ".$_SERVER['SCRIPT_FILENAME'].": Sql: ".$qstring.", Error: ".db_error());
}
$result2 = $stmt;
}
return $stmt;
}
/**
* Begin a transaction
*
* Begin a transaction for databases that support them
* may cause unexpected behavior in databases that don't
*/
function db_begin() {
return db_query("BEGIN WORK");
}
/**
* Commit a transaction
*
* Commit a transaction for databases that support them
* may cause unexpected behavior in databases that don't
*/
function db_commit() {
return db_query("COMMIT");
}
/**
* Roll back a transaction
*
* Rollback a transaction for databases that support them
* may cause unexpected behavior in databases that don't
*/
function db_rollback() {
$str = db_error();
db_query("ROLLBACK");
die('sql error: ' . $str . " ROLLBACK performed....");
}
/**
* Returns the number of rows in this result set
*
* @param $qhandle (string) Query result set handle
*/
function db_num_rows($qhandle) {
// return only if qhandle exists, otherwise 0
if ($qhandle) {
return mysqli_num_rows($qhandle);
} else {
return 0;
}
}
/**
* Frees a database result properly
*
* @param $qhandle (string) Query result set handle
*/
function db_free_result($qhandle) {
return mysqli_free_result($qhandle);
}
/**
* Reset a result set.
*
* Reset is useful for db_fetch_array sometimes you need to start over
*
* @param $qhandle (string) Query result set handle
* @param $row (int) Row number
*/
function db_reset_result($qhandle,$row=0) {
return mysqli_data_seek($qhandle,$row);
}
/**
* Returns a field from a result set
*
* @param $qhandle (string) Query result set handle
* @param $row (int) Row number
* @param $field (string) Field name
*/
function db_result($qhandle,$row,$field) {
//return mysqli_result($qhandle,$row,$field);
if( mysqli_num_rows( $qhandle ) ) {
$x = 0;
while( $array = mysqli_fetch_array( $qhandle, MYSQLI_NUM ) ) {
if( $row == $x++ ) {
return isset( $array[ $field ] ) ? $array[ $field ] : '';
}
}
}
}
/**
* Returns the number of fields in this result set
*
* @param $lhandle (string) Query result set handle
* (!!! Deprecated? Changed the MySQL-Command to match the current syntax)
*/
function db_numfields($lhandle) {
return mysqli_num_fields($lhandle);
}
/**
* Returns the number of fields in this result set
*
* @param $lhandle (string) Query result set handle
* php 3,4,5
*/
function db_num_fields($lhandle) {
return mysqli_num_fields($lhandle);
}
/**
* Returns the number of rows changed in the last query
*
* @param $lhandle (string) Query result set handle
* @param $fnumber (int) Column number
*/
function db_fieldname($lhandle,$fnumber) {
return mysql_field_name($lhandle,$fnumber);
}
/**
* Returns the number of rows changed in the last query
*
* @param $qhandle (string) Query result set handle
*/
function db_affected_rows($qhandle) {
return mysqli_affected_rows($qhandle);
}
/**
* Fetch an array
*
* Returns an associative array from
* the current row of this database result
* Use db_reset_result to seek a particular row
*
* @param $qhandle (string) Query result set handle
*/
function db_fetch_array($qhandle) {
global $conn;
$data = mysqli_stmt_result_metadata($qhandle);
$fields = array();
$out = array();
$fields[0] = &$qhandle;
$count = 1;
while($field = mysqli_fetch_field($data)) {
$fields[$count] = &$out[$field->name];
$count++;
}
call_user_func_array(mysqli_stmt_bind_result, $fields);
mysqli_stmt_fetch($qhandle);
return (count($out) == 0) ? false : $out;
/*if (!$qhandle)
return NULL;
else
return mysqli_fetch_array($conn); */
}
/**
* fetch a row into an array
*
* @param $qhandle (string) Query result set handle
* @param $fnumber (int) Column number
*/
function db_fetch_row($qhandle,$fnumber=0) {
global $stmt;
if ($qhandle)
return mysqli_fetch_row($stmt);
else
return NULL;
}
/**
* Returns the last primary key from an insert
*
* @param $qhandle (string) Query result set handle
* @param $table_name (string) Is the name of the table you inserted into
* @param $pkey_field_name (string) Is the field name of the primary key
*/
function db_insertid($qhandle="",$table_name="",$pkey_field_name="") {
return mysqli_insert_id();
}
function db_insert_id($qhandle="",$table_name="",$pkey_field_name="") {
return mysqli_insert_id();
}
/**
* Returns the last error from the database
*/
function db_error() {
global $conn;
return mysqli_error($conn);
}
/**
* Get the flags associated with the specified field in a result
*
* @param $lhandle (string) Query result set handle
* @param $fnumber (int) Column number
*
* Examples: "not_null", "primary_key", "unique_key", "multiple_key",
* "blob", "unsigned", "zerofill","binary", "enum",
* "auto_increment", "timestamp"
*/
function db_field_flags($lhandle,$fnumber) {
return mysqli_field_flags($lhandle,$fnumber);
}
/**
* Get the type of the specified field
*
* @param $lhandle (string) Query result set handle
* @param $fnumber (int) Column number
*/
function db_field_type($lhandle,$fnumber) {
return mysqli_field_type($lhandle,$fnumber);
}
/**
* Get the length of the specified field
*
* @param $lhandle (string) Query result set handle
* @param $fnumber (int) Column number
*/
function db_field_len($lhandle,$fnumber) {
return mysqli_field_len($lhandle,$fnumber);
}
?>