Location: PHPKode > scripts > MsSql To XML > mssql-to-xml/mssql.inc.php
<?
/*
MsSQL Database Function By Ismet Ozalp
Email:hide@address.com
Please do not remove this.
*/

Class MsSQL {
	
	private $dbname="";
	private $host="";
	private $port="";
	private $user="";
	private $password="";
	private $connection;
	private $metatag = "<META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html\"; charset=\"ISO-8859-1\">";
	
	function __construct() {
		$this->connection=@mssql_connect("$this->host,$this->port",$this->user,$this->password);
		if(!$this->connection){
			echo $this->metatag."Can Not Connect To DB";
			exit();
		}else{
			if(!(@mssql_select_db($this->dbname, $this->connection))){
				echo $this->metatag."Can Not Select The DB";
				exit();
			}
		}
    }
   public function query($query){
   		$qresult=mssql_query($query) or Die("\"$query\" " . "Query Failed!");
   		return $qresult;
   }
   public function getArray($query){
   		$queryResult = $this->query($query);
   		$i=0;
   		while ($object = mssql_fetch_object($queryResult)){
   			foreach($object as $key => $value) {
   				$resultArray[$i][$key]=$value;	
   			}
   		$i++;
   		}
   	return $resultArray;
   }
   public function numrows($query){
   	return	mssql_num_rows($this->query($query));
   }
   public function numOfFields($query){
   	return mssql_num_fields ($this->query($query));
   }
   public function fieldNames($query){
   	$numberOfFields = $this->numOfFields($query);
   	$queryResult=$this->query($query);	
   	$nameArray=array();
   		for($i=0;$i<$numberOfFields;$i++){
   			$name = mssql_fetch_field($queryResult, $i);
   			$nameArray[$i]=$name->name;
   		}
   	return $nameArray;
   }
   private function InitSp($spName){
   		return mssql_init($spName,$this->connection);
   }

   private function executeSp($sp){
   		mssql_execute($sp);
   }
   
   public function SP_CALL($spName,$parameters=Array(),$outputType="Message"){//CALL Stored Procedure
   		$sps=$this->InitSp($spName);
   		$z=0;
   		$outputparams=array();
   		for($i=0;$i<count($parameters);$i++){
   			$isOutput=$parameters[$i]["isOutput"];
   			$isNull=$parameters[$i]["isNull"];
   			$maxlen=$parameters[$i]["maxlen"];
   			$paramName=$parameters[$i]["parameter"];
   			$type=$parameters[$i]["type"];
   			if($isOutput){
   				mssql_bind($sps,$paramName,$outputparams[$z],$type,$isOutput,$isNull);
   				$z++;	   			
   			}else{
   				$variableToSend=$parameters[$i]["variable"];
   				mssql_bind($sps,$paramName,$variableToSend,$type);
   			}
   		}
   		$this->executeSp($sps);
		return $outputparams;		
   }
   public function myAddslashes($str){
   		if (is_array($str)) {
       		foreach($str AS $id => $value) {
           		$str[$id] = myAddslashes($value);
       		}
   		} else {
       		$str = str_replace("'", "''", $str);    
   		}	
   
   	return $str;
    }

    public function myStripslashes($str){
   		if (is_array($str)) {
       		foreach($str AS $id => $value) {
    	       $str[$id] = myStripslashes($value);
    		}
   		} else {
    		$str = str_replace("''", "'", $str);    
   		}
   	return $str;
   }
   function __destruct() {
   		@mssql_close($this->connection);
   }

}
?>
Return current item: MsSql To XML