Jump to content
  • 0

pomoc SA-MP MySQL


Anonimus24

Dotaz

Ahoj chtěl bych se zeptat neustále mi to píše MySQL connect error:
Mám to vyplněné mysql host atd... :D

Spoiler

<?php
	// Funkcia na logovanie
	function logfile( $file = "", $mode = "a", $text = "" )
	{
		$myfile = fopen( $file, $mode ) or exit( "Unable to open file!" );
		fwrite( $myfile, Date( "d.m.Y H:i:s", time() )." - ".$text."\n" );
		fclose( $myfile );
	}
	
	// Funkcia na kód do SMS
	function code( $stat = "SK", $shortcode = "", $error = 0 )
	{		
		if( $stat == "SK" && $error == 1 ) { return ";FREE8877"; }
		else if( $stat == "SK" && $error == 0 ) { return ";".$shortcode; }
		else if( $stat == "CZ" && $error == 1 && mb_strlen( $shortcode ) == 7 ) { return ";FREE".$shortcode; }
		else if( $stat == "CZ" && $error == 1 && mb_strlen( $shortcode ) == 5 ) { return ";FREE90333149"; }
		else if( $stat == "CZ" && $error == 0 && mb_strlen( $shortcode ) == 7 ) { return ";".$shortcode; }
		else if( $stat == "CZ" && $error == 0 && mb_strlen( $shortcode ) == 5 ) { return ";90333149"; }
	}
	function randomCode($length = 10) {
		$characters = '01234';
		$charactersLength = strlen($characters);
		$randomString = '';
		for ($i = 0; $i < $length; $i++) {
			$randomString .= $characters[rand(0, $charactersLength - 1)];
		}
		return $randomString;
	}
	
	$mysqli_host = "";
	$mysqli_user = "";
	$mysqli_pass = "";
	$mysqli_name = "";
	$mysql_prefix = "premium";
	
	$url = filter_input_array( INPUT_GET );
	$url['shortcode'] = intval( trim( $url['shortcode'] ) );
	$url['operator'] = strtoupper( trim( $url['operator'] ) );
	$url['phone'] = trim( $url['phone'] );
	$url['country'] = strtoupper( trim( $url['country'] ) );
	$url['sms'] = trim( $url['sms'] );
	$url['id'] = intval( trim( $url['id'] ) );
	$url['refip'] = $_SERVER['REMOTE_ADDR'];
	
	logfile( "vip_sms_log.txt", "a", "IDSMS: ".$url['id']." | Operator: ".$url['operator']." | Cislo: ".$url['phone']." | Krajina: ".$url['country']." | SMS Cislo: ".$url['shortcode']." | Sprava: ".$url['sms']." | RefIP: ".$url['refip'] );
	
	$db_connect = @mysqli_connect( $mysqli_host, $mysqli_user, $mysqli_pass );
	$db_select = @mysqli_select_db( $mysqli_name );
	if( !$db_connect || !$db_select )
	{ 
		$answer = "Bohuzel nastala chyba v komunikaci, prosim kontaktujte nas.".code( $url['country'], $url['shortcode'], 1 );
		header( "Content-type:text/plain" );
		header( "Content-length:".mb_strlen( $answer ) );
		logfile( "vip_sms_log.txt", "a", "MySQL Connect Error (".mysql_error().") ".mysql_errno() );
		exit( $answer );
	}
	
	if( empty( $url ) && !is_array( $url ) )
	{
		$answer = "Bohuzel nastala chyba v pozadavku, prosim kontaktujte nas.".code( $url['country'], $url['shortcode'], 1 );
		header( "Content-type:text/plain" );
		header( "Content-length:".mb_strlen( $answer ) );
		logfile( "vip_sms_log.txt", "a", "Vonkajsia chyba, z vonkajsej strany prisiel neznamy request." );
		exit( $answer );
	}
	
	if( !preg_match( "/ PM GAMERAGE /", $url['sms'] ) )
	{
		$answer = "Prijela k nam SMS ktera byla poslana ve zlym tvaru, kontaktujte nas.".code( $url['country'], $url['shortcode'], 1 );
		header( "Content-type:text/plain" );
		header( "Content-length:".mb_strlen( $answer ) );
		logfile( "vip_sms_log.txt", "a", "Vonkajsia chyba, bola zle zadana nespravna SMS, zadane: ".$url['sms'] );
		exit( $answer );
	}
	
	$sms = explode( " ", $url['sms'] );
	
	if( !( preg_match( "/^[a-zA-Z0-9_]+$/", $sms[2] ) ) )
	{
		$answer = "Vase jmeno neni dle specifikace, podivejte se to navodu prosim.".code( $url['country'], $url['shortcode'], 1 );
		header( "Content-type:text/plain" );
		header( "Content-length:".mb_strlen( $answer ) );
		logfile( "vip_sms_log.txt", "a", "Nebyl dorucen SMS aktivovaci kod protoze jmeno do SMS bylo napsano nasledovne: ".$sms[2] );
		exit( $answer );
	}
	
	$url['sms'] = trim( $sms[ 2 ] );
	
	if( $url['shortcode'] != "88770500" && $url['shortcode'] != "90333" )
	{
		$answer = "Litujeme, ale Vami zaslana SMS na toto cislo nemuze byt zpracovana, kontaktuje nas.".code( $url['country'], $url['shortcode'], 1 );
		header( "Content-type:text/plain" );
		header( "Content-length:".mb_strlen( $answer ) );
		logfile( "vip_sms_log.txt", "a", "Nebyl dorucen SMS aktivovaci kod protoze SHORTCODE byl zly. Zadane: ".$url['shortcode'] );
		exit( $answer );
	}
	
	$result = @mysqli_query( "SELECT * FROM `".$mysql_prefix."sms_keys` WHERE `sms_name`='".$url['sms']."' AND `sms_phone`='".$url['phone']."' LIMIT 1" ) or die (mysqli_error());
	$rows = @mysqli_num_rows( $result );
	if( $rows )
	{
		$data = @mysqli_fetch_assoc( $result );
		$answer = "Nasledujici SMS kod vam byl zaslan, a jiz ceka k pouziti: ".$data['sms_key']." a jmeno: ".$url['sms']." v aktivatoru.".code( $url['country'], $url['shortcode'], 1 );
		header( "Content-type:text/plain" );
		header( "Content-length:".mb_strlen( $answer ) );
		logfile( "vip_sms_log.txt", "a", "V systemu sme rozpoznali jeste nepouzity kod na zaslane jmeno: ".$url['sms']." a mobil: ".$url['phone']." s kodom: ".$data['sms_key'] );
		exit( $answer );
	}
	else
	{
		$key = randomCode( 10 );
		$result = @mysqli_query( "INSERT INTO `".$mysqli_prefix."sms_keys` (`sms_name`, `sms_shortcode`, `sms_phone`, `sms_key`, `sms_country`) VALUES ('".mysqli_real_escape_string( $url['sms'] )."', '".mysqli_real_escape_string( $url['shortcode'] )."', '".mysqli_real_escape_string( $url['phone'] )."', '".mysqli_real_escape_string( $key )."', '".$url['country']."')" ) or die (mysqli_error());
		$answer = "Dakujeme za SMS pre aktivaciu VIP pouzite nasledujici kod: ".$key." a jmeno: ".$url['sms']." v aktivatoru.".code( $url['country'], $url['shortcode'], 0 );
		header( "Content-type:text/plain" );
		header( "Content-length:".mb_strlen( $answer ) );
		logfile( "vip_sms_log.txt", "a", "Byl vygenerovany novy SMS VIP kod: ".$key." pro jmeno: ".$url['sms']." a mobil: ".$url['phone'] );
		exit($answer);
	}
?>

 

 

Link to comment
Share on other sites

1 odpověd na tuto otázku

Recommended Posts

  • 0
  • Globální moderátor
try {
	$conn = new PDO('mysql:host='.$host.';dbname='.$dat.';charset=utf8', $user, $pass);
	$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
	$conn->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
} catch (Exception $e) {
	$e->getMessage();
}

 

je to hodně starej kód, ale takhle já kontroloval připojení.

 

Dále jsem se připojoval: 

$db = mysqli_connect("$host", "$user", "$pass", "$dat");
// Check connection
if (mysqli_connect_errno()) {
    die("Connection failed: " . mysqli_connect_error());
}

 

A tahal z databáze:

$stmt = $db->prepare("SELECT id, value FROM data");
$stmt->execute();
$stmt->bind_result($id,$value);
while($stmt->fetch())
{
	'<p>' . $id . ': ' . $value . '</p>'
}

 

Každopádně nevím co to hází za chybu, nenapsal jsi. Každopádně mrkni jaký loginy a z jakých míst se můžeš připojovat. Jestli třeba nemáš povolenej jen lokální access...

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...