Location: PHPKode > projects > Internet Task Management System > itms_mysql_build_0111/db_tools.php
<?php

/*
 * db_tools.php
 * This file will contain the basic functions needed to connect and disconnect from the database,
 * as well as issue queries to the database.
 *
 * ITMS ValleyData source file version 1.0 May 11, 2001
 *
 *
 *
 * Internet Task Management System: An online system used for recording information about and assigning tasks and processes.
 * Copyright (C) 2001  ValleyData Programming Group
 *
 * 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.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *
 * See file named "gpl.txt" included with source code or
 * visit http://www.gnu.org/copyleft/gpl.txt on the internet.
 */

include("config.php");

//to specify which DB to use
function db_use()
{
	if(func_num_args() == 0)
	{
		global $DB;
		$dbname = $DB;
	}
	else if(func_num_args() == 1)
		$dbname = func_get_arg(0);
    @mysql_select_db($dbname)
        or error_out("Could not use database: " . $dbname, "LOG_ERR");
}

//to open a connection to the DB
function db_open()
{
	if(func_num_args() == 0)
	{
		global $DB_HOST;
		global $DB_USERNAME;
		global $DB_PASSWORD;
		$hostname = $DB_HOST;
		$username = $DB_USERNAME;
		$password = $DB_PASSWORD;
	}
	else if(func_num_args() == 3)
	{
		$hostname = func_get_arg(0);
		$username = func_get_arg(1);
		$password = func_get_arg(2);
	}
    return @mysql_connect($hostname, $username, $password)
        or error_out("Could not connect to db using hostname: $hostname, username: $username", "LOG_ERR");
}

//to close the connection to the DB
function db_close()
{
    @mysql_close()
        or error_out("Could not close db", "LOG_WARNING");
}

//to issue a query to a connected DB
function db_query($query, $report_errors = "true")
{
	if($report_errors != "NO_ERR")
	{
    $resultset = @mysql_query($query)
        or error_out("Could not execute query: " . $query, "LOG_ERR");
	}
	else //don't report errors
		$resultset = @mysql_query($query);
    return $resultset;
}

//returns a row from the result of a sucessful call to the db_query function
function db_fetch_row($resultset)
{
    return @mysql_fetch_array($resultset);
}


?>
Return current item: Internet Task Management System