1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
|
<?php
/**************************************************************************
* This file is part of the WebIssues Server program
* Copyright (C) 2006 Michał Męciński
* Copyright (C) 2007-2008 WebIssues Team
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
**************************************************************************/
require_once( 'logging.inc.php' );
switch ( $config[ 'db_engine' ] ) {
case 'mysql':
if ( function_exists( 'mysql_connect' ) )
require_once( 'database-mysql.inc.php' );
break;
case 'mysqli':
if ( function_exists( 'mysqli_connect' ) )
require_once( 'database-mysqli.inc.php' );
break;
case 'pgsql':
if ( function_exists( 'pg_connect' ) )
require_once( 'database-pgsql.inc.php' );
break;
case 'mssql':
if ( class_exists( 'COM' ) && version_compare( PHP_VERSION, '5.0', '>=' ) )
require_once( 'database-mssql.inc.php' );
break;
}
function wi_check_database()
{
return function_exists( 'wi_db_connect' );
}
function wi_open_database()
{
global $config;
set_magic_quotes_runtime( 0 );
if ( !wi_db_connect( $config[ 'db_host' ], $config[ 'db_database' ], $config[ 'db_user' ], $config[ 'db_password' ] ) )
return false;
ignore_user_abort( true );
return true;
}
function wi_query( $query )
{
$args = func_get_args();
array_shift( $args );
return wi_query_args( $query, $args );
}
function wi_query_row( $query )
{
if ( func_num_args() > 1 ) {
$args = func_get_args();
array_shift( $args );
} else {
$args = null;
}
$rs = wi_query_args( $query, $args );
if ( !$rs )
return false;
return wi_db_fetch_assoc( $rs );
}
function wi_query_args( $query, $args )
{
global $config;
$query = str_replace( '{', $config[ 'db_prefix' ], $query );
$query = str_replace( '}', '', $query );
$query = wi_build_query( $query, $args );
$rs = wi_db_query( $query );
return $rs;
}
function wi_build_query( $query, $args )
{
$result = '';
$index = 0;
$parts = preg_split( '/(%(?:\d+\\$)?[a-z])/', $query, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY );
foreach ( $parts as $part ) {
if ( $part{0} == '%' ) {
$type = substr( $part, -1, 1 );
if ( strlen( $part ) > 2 )
$index = (int)substr( $part, 1, -2 );
else
$index = $index + 1;
$arg = $args[ $index - 1 ];
$result .= wi_db_escape_arg( $arg, $type );
} else {
$result .= $part;
}
}
return $result;
}
function wi_fetch( $rs )
{
return wi_db_fetch_assoc( $rs );
}
function wi_unescape_blob( $data )
{
return wi_db_unescape_blob( $data );
}
function wi_insert_id( $table, $column )
{
global $config;
return wi_db_insert_id( $config[ 'db_prefix' ] . $table, $column );
}
function wi_table_exists( $table )
{
global $config;
return wi_db_table_exists( $config[ 'db_prefix' ] . $table );
}
|