Login   Register  
PHP Classes
elePHPant
Icontem

File: changelog_access.inc

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Mark Williamson  >  dbApiCreate  >  changelog_access.inc  >  Download  
File: changelog_access.inc
Role: Sample output
Content type: text/plain
Description: Database Access Library created using dbApiCreate.inc
Class: dbApiCreate
Creates mysql database access libraries in php
Author: By
Last change:
Date: 2003-03-07 17:11
Size: 6,255 bytes
 

Contents

Class file image Download
<?php

	   /////////////////////////////////////////////////////////////////////////////////////
	  // Api Created using dbApiCreate.inc auto-access-lib generation by Mark Williamson //
	 // fate_amendable_to_change@yahoo.com available from www.phpclasses.org            //
	/////////////////////////////////////////////////////////////////////////////////////


/////////////////////////////////////////
// Function: get_named_connection('database')
// Purpose: Connects to specified database 
// Returns: $connection handle for mysql_query($sql, $connection) 
/////////////////////////////////////////
function get_named_connection($db){
	//Recommend moving this function outside webroot and including it to protect passwords
	$connection = mysql_pconnect('127.0.0.1', 'SOMEUSER', 'SOMEPASS');
	$selectdb = mysql_select_db($db);
	return($connection);
}


/////////////////////////////////////////
// Function: add_to_changes()
// Purpose: Adds a row to changes
// Returns: MySQL Insert ID
/////////////////////////////////////////
function add_to_changes($version_num, $version_tag, $change_desc, $userid, $timestamp){

	$version_num = addslashes($version_num);
	$version_tag = addslashes($version_tag);
	$change_desc = addslashes($change_desc);
	$userid = addslashes($userid);
	$timestamp = addslashes($timestamp);
	$connection = get_named_connection("changelog");
	$sql = "INSERT INTO changes (version_num, version_tag, change_desc, userid, timestamp)
		VALUES ('$version_num', '$version_tag', '$change_desc', '$userid', '$timestamp')";

	 $result = mysql_query($sql, $connection) or die(mysql_error($connection));

	 $insert_id = mysql_insert_id($connection);
	return($insert_id);
}



/////////////////////////////////////////
// Function: changes_generic_update()
// Purpose: update specified fields with values in changes
// Returns: mysql_affected_rows() 
/////////////////////////////////////////
function changes_generic_update($find, $matches){
	$connection = get_named_connection("changelog");
	$x = count($find); $i=0; $y=count($matches); $n=0;
	foreach($find as $key=>$val){
		$updsql .= "$key='$val'";
		if($i<$x-1){
			$updsql.=",";
		}	
		++$i;	
	 }
	foreach($matches as $key=>$val){
		$match_sql .= "$key='$val'";
		if($n<$y-1){
			$match_sql.=",";
		}	
		++$n;	
	 }
	$sql = "UPDATE changes SET $updsql WHERE $match_sql";
	$result = mysql_query($sql, $connection) or die(mysql_error($connection));

	$return = mysql_affected_rows($result);
	 return($return);
}


/////////////////////////////////////////
// Function: update_changes()
// Purpose: Updates specified row in changes
// Returns: True on success (die on error) 
/////////////////////////////////////////
function update_changes($change_id, $version_num, $version_tag, $change_desc, $userid, $timestamp){

	$connection = get_named_connection("changelog");
	$sql = "UPDATE changes SET 
		version_num = '$version_num', version_tag = '$version_tag', change_desc = '$change_desc', userid = '$userid', timestamp = '$timestamp'
		WHERE change_id = '$change_id'";

	$result = mysql_query($sql, $connection) or die(mysql_error($connection));

	return(TRUE);
}



/////////////////////////////////////////
// Function: delete_from_changes()
// Purpose: Deletes specified row in changes
// Returns: True on success (die on error) 
/////////////////////////////////////////
function delete_from_changes($change_id){
 	$change_id = addslashes($change_id);
	$connection = get_named_connection("changelog");
	$sql = "DELETE * FROM changes WHERE change_id = '$change_id'";
	$result = mysql_query($sql, $connection) or die(mysql_error($connection));

	return(TRUE);
}



/////////////////////////////////////////
// Function: changes_find_by_()
// Purpose: Finds rows with specified value for  in changes
// Returns: struct of all matching rows 
/////////////////////////////////////////
function changes_find_by_change_id($change_id){
	$change_id = addslashes($change_id);
	$connection = get_named_connection("changelog");
	$sql = "SELECT * FROM changes WHERE  change_id = '$change_id'  ";
	$result = mysql_query($sql, $connection) or die(mysql_error($connection));

	$return = array();
	while($rows = mysql_fetch_array($result, MYSQL_ASSOC)){
		 $return[] = $rows;
	}
	 return($return);
}


/////////////////////////////////////////
// Function: changes_find_by_change_id()
// Purpose: Finds rows with specified value for change_id in changes
// Returns: struct of all matching rows 
/////////////////////////////////////////
function changes_find_by_userid($userid){
	$userid = addslashes($userid);
	$connection = get_named_connection("changelog");
	$sql = "SELECT * FROM changes WHERE  userid LIKE '%$userid%'  ";
	$result = mysql_query($sql, $connection) or die(mysql_error($connection));

	$return = array();
	while($rows = mysql_fetch_array($result, MYSQL_ASSOC)){
		 $return[] = $rows;
	}
	 return($return);
}


/////////////////////////////////////////
// Function: changes_find_by_userid()
// Purpose: Finds rows with specified value for userid in changes
// Returns: struct of all matching rows 
/////////////////////////////////////////
function changes_find_by_change_desc($change_desc){
	$change_desc = addslashes($change_desc);
	$connection = get_named_connection("changelog");
	$sql = "SELECT * FROM changes WHERE  change_desc LIKE '%$change_desc%'  ";
	$result = mysql_query($sql, $connection) or die(mysql_error($connection));

	$return = array();
	while($rows = mysql_fetch_array($result, MYSQL_ASSOC)){
		 $return[] = $rows;
	}
	 return($return);
}


/////////////////////////////////////////
// Function: changes_generic_find()
// Purpose: Finds rows with specified value for specified fields in changes
// Returns: struct of all matching rows 
/////////////////////////////////////////
function changes_generic_find($find){
	$connection = get_named_connection("changelog");
	$x=0; $n=count($find)-1;;
	foreach($find as $key=>$val){;
		$whereSQL .= "$key = \"$val\"";
		$whereSQL.=($x<$n)?" AND ":"\n";
		$x++;
	}
	 $sql = "SELECT * FROM changes WHERE $whereSQL ";
	$result = mysql_query($sql, $connection) or die(mysql_error($connection));

	$return = array();
	while($rows = mysql_fetch_array($result, MYSQL_ASSOC)){
		 $return[] = $rows;
	}
	 return($return);
}


?>