Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

Elnata COsta

Conexão MySql entre VB.NET e PHP

Recommended Posts

Então pessoal tenho um programa aqui em que ele usa um arquivo PHP para se conectar ao DB do site (Pelo meno eu acho), Pq no programa tem a opção de escolher a URL, e dependendo a URL que você coloca no programa, ela conecta ao DB [MySql] do site se tiver o módulo php!

 

Eu gostaria de saber como posso fazer isso? Ele tbm usa esse sistema para fazer login no programa!!

 

Se vocês puderem me ajudar ficarei muito grato! :yes:

 

 

Se ajudar irei postar abaixo o arquivo php:

 

<?php

class kACARS extends CodonModule
{
 
public function index()
	{
		if ( $_SERVER['REQUEST_METHOD'] === 'POST' )
		{ 
    	    $postText = file_get_contents('php://input');		
			
			$rec_xml = $postText;					 
			$xml = simplexml_load_string($rec_xml);
			
			if(!is_numeric($xml->verify->pilotID))
					{
						# see if they are a valid pilot:
						preg_match('/^([A-Za-z]*)(\d*)/', $xml->verify->pilotID, $matches);
						$pilot_code = $matches[1];
						$pilotid = intval($matches[2]) - Config::Get('PILOTID_OFFSET');
					}
					else
					{
						$pilotid = $xml->verify->pilotID;
					}				
			
					$pilotinfo = PilotData::getPilotData($pilotid);

			
			switch($xml->switch->data)
			{
				case verify:		
					$results = Auth::ProcessLogin($xml->verify->pilotID, $xml->verify->password);		
					if ($results)
					{						
						$params = array('loginStatus' => '1');					
						//echo 1;
					}
					else
					{
						$params = array('loginStatus' => '0');
						//echo 0;
					}
					
					$send = self::sendXML($params);
											
					break;
					
				case getBid:
			
					$biddata = self::getLatestBid2($pilotid);
			
					$aircraftinfo = OperationsData::getAircraftByReg($biddata->registration);
					$dep = OperationsData::getAirportInfo($biddata->depicao);
					$arr = OperationsData::getAirportInfo($biddata->arricao);
										
					if(count($biddata) == 1)
					{		
						if($aircraftinfo->enabled == 1)
						{
							$params = array(
								'flightStatus' 	   	=> '1',
								'flightNumber'     	=> $biddata->code.$biddata->flightnum,
								'aircraftReg'      	=> $biddata->registration,
								'aircraftICAO'     	=> $aircraftinfo->icao,
								'aircraftFullName' 	=> $aircraftinfo->fullname,
								'flightLevel'      	=> $biddata->flightlevel,
								'aircraftMaxPax'   	=> $aircraftinfo->maxpax,
								'aircraftCargo'    	=> $aircraftinfo->maxcargo,
								'depICAO'          	=> $biddata->depicao,
								'arrICAO'          	=> $biddata->arricao,
								'route'            	=> $biddata->route,
								'depTime'          	=> $biddata->deptime,
								'arrTime'          	=> $biddata->arrtime,
								'flightTime'       	=> $biddata->flighttime,
								'flightType'       	=> $biddata->flighttype,
								'aircraftName'     	=> $aircraftinfo->name,
								'aircraftRange'    	=> $aircraftinfo->range,
								'aircraftWeight'   	=> $aircraftinfo->weight,
								'aircraftCruise'   	=> $aircraftinfo->cruise,
								'depLat'			=> $dep->lat,
								'depLng'			=> $dep->lng,
								'arrLat'			=> $arr->lat,
								'arrLng'			=> $arr->lng
								);					
						}
						else
						{	
							$params = array(
								'flightStatus' 	   => '3');		// Aircraft Out of Service.							
						}			
					}		
					else		
					{
							$params = array(
								'flightStatus' 	   => '2');	// You have no bids!								
					}
					
					$send = self::sendXML($params);
					
					break;
					
				case getFlight:
				
						$flightNumber = $xml->pirep->flightNumber;												
						self::findFlight($flightNumber);
						break;
					
				case getFlightInfo:				
						
						$flightNumber = $xml->sch->flightNumber;						
						self::findFlight($flightNumber);
						break;

				case liveupdate:	
				
						$lat = str_replace(",", ".", $xml->liveupdate->latitude);
						$lon = str_replace(",", ".", $xml->liveupdate->longitude);					
      		
						# Get the distance remaining
						$depapt = OperationsData::GetAirportInfo($xml->liveupdate->depICAO);
						$arrapt = OperationsData::GetAirportInfo($xml->liveupdate->arrICAO);
						$dist_remain = round(SchedulesData::distanceBetweenPoints(
										$lat, $lon, $arrapt->lat, $arrapt->lng));
	
						# Estimate the time remaining
						if($xml->liveupdate->groundSpeed > 0)
						{
							$Minutes = round($dist_remain / $xml->liveupdate->groundSpeed * 60);
							$time_remain = self::ConvertMinutes2Hours($Minutes);
						}
						else
						{
							$time_remain = '00:00';
						}
		
						$fields = array(
							'pilotid'        =>$pilotid,
							'flightnum'      =>$xml->liveupdate->flightNumber,
							'pilotname'      =>'',
							'aircraft'       =>$xml->liveupdate->registration,
							'lat'            =>$lat,
							'lng'            =>$lon,
							'heading'        =>$xml->liveupdate->heading,
							'alt'            =>$xml->liveupdate->altitude,
							'gs'             =>$xml->liveupdate->groundSpeed,
							'depicao'        =>$xml->liveupdate->depICAO,
							'arricao'        =>$xml->liveupdate->arrICAO,
							'deptime'        =>$xml->liveupdate->depTime,
							'arrtime'        =>'',
							'route'          =>$xml->liveupdate->route,
							'distremain'     =>$dist_remain,
							'timeremaining'  =>$time_remain,
							'phasedetail'    =>$xml->liveupdate->status,
							'online'         =>$xml->liveupdate->online,
							'messagelog'     =>$xml->liveupdate->messagelog,
							'client'         =>'kACARS',
						);
				
						ACARSData::UpdateFlightData($pilotid, $fields);
						
						$params = array(
								'distRemain'  => $dist_remain,
								'timeRemain'  => $time_remain								
								);
								
						$send = self::sendXML($params);
				
						break;
						
				case pirep:						
			
						$flightinfo = SchedulesData::getProperFlightNum($xml->pirep->flightNumber);
						$code = $flightinfo['code'];
						$flightnum = $flightinfo['flightnum'];	
		
						# Make sure airports exist:
						#  If not, add them.
												
						if(!OperationsData::GetAirportInfo($xml->pirep->depICAO))
						{
							OperationsData::RetrieveAirportInfo($xml->pirep->depICAO);
						}
		
						if(!OperationsData::GetAirportInfo($xml->pirep->arrICAO))
						{
							OperationsData::RetrieveAirportInfo($xml->pirep->arrICAO);
						}
		
						# Get aircraft information
						$reg = trim($xml->pirep->registration);
						$ac = OperationsData::GetAircraftByReg($reg);
		
						# Load info
						/* If no passengers set, then set it to the cargo */
						$load = $xml->pirep->pax;
						if(empty($load))
							$load = $xml->pirep->cargo;						
		
						/* Fuel conversion - kAcars only reports in lbs */
						$fuelused = $xml->pirep->fuelUsed;
						if(Config::Get('LiquidUnit') == '0')
						{
							# Convert to KGs, divide by density since d = mass * volume
							$fuelused = ($fuelused * .45359237) / .8075;
						}
						# Convert lbs to gallons
						elseif(Config::Get('LiquidUnit') == '1')
						{
							$fuelused = $fuelused * 6.84;
						}
						# Convert lbs to kgs
						elseif(Config::Get('LiquidUnit') == '2')
						{
							$fuelused = $fuelused * .45359237;
						}
						
						foreach($xml->report as $report)  
						{

							$rawdata['points'][] = array(
								'name'          => (string)$report->name,
								'time'			=> (string)$report->time,
								'lat'           => (string)$report->lat,
								'lng'           => (string)$report->lng,
								'alt'           => (string)$report->alt,
								'head'          => (string)$report->head,
								'gs'            => (string)$report->gs,
								'phase'         => (string)$report->phase,
								'warning'       => (string)$report->warning,
								'warningdetail' => (string)$report->warningdetail
								);
						}

						$data = array('pilotid'=>$pilotid,
								'code'				=>$code,
								'flightnum'			=>$flightnum,
								'depicao'			=>$xml->pirep->depICAO,
								'arricao'			=>$xml->pirep->arrICAO,
								'aircraft'			=>$ac->id,
								'flighttime'		=>$xml->pirep->flightTime,
								'submitdate'		=>'NOW()',
								'comment'			=>$xml->pirep->comments,
								'fuelused'			=>$fuelused,
								'route'          	=>$xml->liveupdate->route,
								'source'			=>'kACARS',
								'load'				=>$load,
								'landingrate'		=>$xml->pirep->landing,
								'rawdata'			=>$rawdata,
								'log'				=>$xml->pirep->log);							
		
						$ret = ACARSData::FilePIREP($pilotid, $data);
						
						$last = PIREPData::getLastReports($pilotid, 1);		
		
						if ($ret)
						{
						
							$params = array(
								'pirepStatus' 	   => '1',
								'pirepID'          => $last->pirepid);	// Pirep Filed!							
						}
						else
						{
							$params = array(
								'pirepStatus' 	   => '2');	// Please Try Again!							
							
						}
						$send = self::sendXML($params);
						
						break;
				
				case aircraft:
					
						self::getAllAircraft();
						break;	
						
				case airport:
				
						self::getAllAirports();
						break;
						
				case aircraftinfo:
						
						$aircraftinfo = OperationsData::getAircraftByReg($xml->pirep->registration);
			
						
							$params = array(								
								'aircraftReg'      => $aircraftinfo->registration,
								'aircraftICAO'     => $aircraftinfo->icao,
								'aircraftFullName' => $aircraftinfo->fullname,								
								'aircraftMaxPax'   => $aircraftinfo->maxpax,
								'aircraftCargo'    => $aircraftinfo->maxcargo,								
								'aircraftName'     => $aircraftinfo->name,
								'aircraftRange'    => $aircraftinfo->range,
								'aircraftWeight'   => $aircraftinfo->weight,
								'aircraftCruise'   => $aircraftinfo->cruise
								);	
						
						$send = self::sendXML($params);
						break;
						
				case schedules:
					
						self::getAllSchedules($pilotinfo->ranklevel, $xml->sch->depICAO);
						break;
						
				case schedules_AC:
					
						self::getAllSchedules_AC($pilotinfo->ranklevel, $xml->sch->aircraft);
						break;
						
				case 'bidFlight':
				
						$biddata = self::getLatestBid2($pilotid);
						
						if($biddata && DISABLE_BIDS_ON_BID) { 
							$bidStatus = 2;
						} else {
							$ret = SchedulesData::AddBid($pilotid, $xml->sch->routeid);
							if($ret == true) 							
								$bidStatus = 1;
							else 								
								$bidStatus = 0;
						}
						
						$params = array('bidStatus' => $bidStatus);
						$send = self::sendXML($params);
						break;	


			}
			
		}
	}
	
	public function ConvertMinutes2Hours($Minutes)
	{
    	if ($Minutes < 0)
    	{
    	    $Min = Abs($Minutes);
    	}
    	else
    	{
    	    $Min = $Minutes;
    	}
    	$iHours = Floor($Min / 60);
    	$Minutes = ($Min - ($iHours * 60)) / 100;
    	$tHours = $iHours + $Minutes;
    	if ($Minutes < 0)
    	{
    	    $tHours = $tHours * (-1);
    	}
    	$aHours = explode(".", $tHours);
    	$iHours = $aHours[0];
    	if (empty($aHours[1]))
    	{
    	    $aHours[1] = "00";
    	}
    	$Minutes = $aHours[1];
    	if (strlen($Minutes) < 2)
    	{
    	    $Minutes = $Minutes ."0";
    	}
    	$tHours = $iHours .":". $Minutes;
    	return $tHours;
	}
	
	public function getLatestBid2($pilotid)
	{
		$pilotid = DB::escape($pilotid);
		
		$sql = 'SELECT s.*, b.bidid, a.id as aircraftid, a.name as aircraft, a.registration, a.maxpax, a.maxcargo
				FROM '.TABLE_PREFIX.'schedules s, 
					 '.TABLE_PREFIX.'bids b,
					 '.TABLE_PREFIX.'aircraft a
				WHERE b.routeid = s.id 
					AND s.aircraft=a.id
					AND b.pilotid='.$pilotid.'
				ORDER BY b.bidid ASC LIMIT 1';
		
		return DB::get_row($sql);
	}
	
	public function sendXML($params)
	{
		$xml = new SimpleXMLElement("<sitedata />");
		
		$info_xml = $xml->addChild('info');
		foreach($params as $name => $value)
		{
			$info_xml->addChild($name, $value);
		}
		
		header('Content-type: text/xml'); 		
		$xml_string = $xml->asXML();
		echo $xml_string;
		
		# For debug
		#$this->log("Sending: \n".print_r($xml_string, true), 'kacars');
		
		return;	
	}
	
	public static function getAllAircraft()
	{
		$results = OperationsData::getAllAircraft(true);
	
		$xml = new SimpleXMLElement("<aircraftdata />");
		
		$info_xml = $xml->addChild('info');
		
		foreach($results as $row)
		{
			$info_xml->addChild('aircraftICAO', $row->icao);
			$info_xml->addChild('aircraftReg', $row->registration);
			$info_xml->addChild('aircraftName', $row->name);
		}
			
			
		header('Content-type: text/xml'); 		
			echo $xml->asXML();
	
	}
	
	public static function getAllAirports()
	{
		$results = OperationsData::getAllAirports();
	
		$xml = new SimpleXMLElement("<airportdata />");
		
		$info_xml = $xml->addChild('info');
		
		foreach($results as $row)
		{
			$info_xml->addChild('airportICAO', $row->icao);
			$info_xml->addChild('airportName', $row->name);
		}
			
			
		header('Content-type: text/xml'); 		
			echo $xml->asXML();
	
	}
	
	public static function getAllSchedules($ranklevel, $icao)
	{
		$params['s.depicao'] = $icao;
		$params['s.enabled'] = 1;

		$results = SchedulesData::findSchedules($params);		
	
		$xml = new SimpleXMLElement("<scheduledata />");
		
		$info_xml = $xml->addChild('info');	
		
		if($results)
		{
			foreach($results as $row)		
			{
				if ($row->aircraftlevel > $ranklevel) continue;
				
				// uncomment the following section to show only todays flights
				
				/*
				$row->daysofweek = str_replace('7', '0', $row->daysofweek);	
				if(strpos($row->daysofweek, date('w')) === false)
					continue;
				*/
				
				if(DISABLE_SCHED_ON_BID && $row->bidid != 0) continue;
			
				$info = OperationsData::getAircraftByReg($row->registration);
				$info_xml->addChild('id', $row->id);
				$info_xml->addChild('flightnumber', $row->code.$row->flightnum);
				$info_xml->addChild('aircraft', $info->icao);
				$info_xml->addChild('depicao', $row->depicao);
				$info_xml->addChild('depname', $row->depname);			
				$info_xml->addChild('arricao', $row->arricao);
				$info_xml->addChild('arrname', $row->arrname);
				$info_xml->addChild('flighttime', $row->flighttime);
			}
		}			
			
		header('Content-type: text/xml'); 		
			echo $xml->asXML();	
	}
	
	public static function getAllSchedules_AC($ranklevel, $icao)
	{
		$params['a.icao'] = $icao;
		$params['s.enabled'] = 1;

		$results = SchedulesData::findSchedules($params);		
	
		$xml = new SimpleXMLElement("<scheduledata />");
		
		$info_xml = $xml->addChild('info');	
		$info_xml = $xml->addChild('test', $icao);
		
		if($results)
		{
			foreach($results as $row)		
			{
				if ($row->aircraftlevel > $ranklevel) continue;
				
				// uncomment the following section to show only todays flights
				
				/*
				$row->daysofweek = str_replace('7', '0', $row->daysofweek);	
				if(strpos($row->daysofweek, date('w')) === false)
					continue;
				*/
				
				$info = OperationsData::getAircraftByReg($row->registration);
				$info_xml->addChild('id', $row->id);
				$info_xml->addChild('flightnumber', $row->code.$row->flightnum);
				$info_xml->addChild('aircraft', $info->icao);
				$info_xml->addChild('depicao', $row->depicao);
				$info_xml->addChild('depname', $row->depname);			
				$info_xml->addChild('arricao', $row->arricao);
				$info_xml->addChild('arrname', $row->arrname);
				$info_xml->addChild('flighttime', $row->flighttime);
			}
		}			
			
		header('Content-type: text/xml'); 		
			echo $xml->asXML();	
	}
	
	public static function findFlight($flightNumber)
	{
		$flightinfo = SchedulesData::getProperFlightNum($flightNumber);
						
		$params['s.code'] = $flightinfo['code'];
		$params['s.flightnum'] = $flightinfo['flightnum'];
		$params['s.enabled'] = 1;
 		$biddata = SchedulesData::findSchedules($params);
			
		$aircraftinfo = OperationsData::getAircraftByReg($biddata[0]->registration);
	
		if(count($biddata) == 1)
		{		
			$params = array(
				'flightStatus' 	   	=> '1',
				'flightNumber'     	=> $biddata[0]->code.$biddata[0]->flightnum,
				'aircraftReg'      	=> $biddata[0]->registration,
				'aircraftICAO'     	=> $aircraftinfo->icao,
				'aircraftFullName' 	=> $aircraftinfo->fullname,
				'flightLevel'      	=> $biddata[0]->flightlevel,
				'aircraftMaxPax'   	=> $aircraftinfo->maxpax,
				'aircraftCargo'    	=> $aircraftinfo->maxcargo,
				'depICAO'          	=> $biddata[0]->depicao,
				'arrICAO'          	=> $biddata[0]->arricao,
				'route'            	=> $biddata[0]->route,
				'depTime'          	=> $biddata[0]->deptime,
				'arrTime'          	=> $biddata[0]->arrtime,
				'flightTime'       	=> $biddata[0]->flighttime,
				'flightType'       	=> $biddata[0]->flighttype,
				'aircraftName'     	=> $aircraftinfo->name,
				'aircraftRange'    	=> $aircraftinfo->range,
				'aircraftWeight'   	=> $aircraftinfo->weight,
				'aircraftCruise'   	=> $aircraftinfo->cruise,				
				'depLat'			=> $biddata[0]->deplat,
				'depLng'			=> $biddata[0]->deplng,
				'arrLat'			=> $biddata[0]->arrlat,
				'arrLng'			=> $biddata[0]->arrlng

				);								
															
		}			
		else		
		{	
			$params = array(
				'flightStatus' 	   => '2');								
		}
				
		$send = self::sendXML($params);
		
		return;
		
	}

}

 

 

Compartilhar este post


Link para o post
Compartilhar em outros sites

Verdade amigo foi o que eu fiz no meu projeto anterior. Mas isso facilitaria em muito pois é um projeto de administração de linha aérea virtual! E por ter bastante eu apenas mudaria a URL no meu programa! :yes: e tbm o php enviaria dados XML para o programa assim tbm como o VB.NET enviaria dados para o php q mandava para o server! s srsrs mas vlww brow....

Compartilhar este post


Link para o post
Compartilhar em outros sites

Você pode jogar todos os métodos de conexão MySQL dentro de uma classe pública, dentro da qual você criaria uma propriedade que permitisse você mudar rapidamente as conexões.

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.