Location: PHPKode > projects > Local Lyric Displayer > lyrics/functions.php
<?
function dbconnect() {
	$mysql_connection_link = mysql_connect ("localhost", "huzursuz", "katana") or die ("<span class=\"error\">MySQL Database'e Baðlantý Kurulamadý</span>");
	$mysql_connect = "1";
	mysql_close ($mysql_connection_link);
	return $mysql_connect;
}

function userkontrol($kullanici_adi,$sifre,$hash) {
	//echo $kullanici_adi . "<br>" . $sifre;
	if ($hash == "hashed") {
		$kont_sifresi = $sifre;
	} else {
		$kont_sifresi = md5($sifre);
	}
	$user_kontrol_sql = "Select * from users where UserName = '" . $kullanici_adi . "' and UserPassword = '" . $kont_sifresi . "'";
	mysql_select_db("lld");
	//echo "<br><span class=\"error\">" . $user_kontrol_sql . "</span><br>";
	$user_kontrol_result = mysql_query($user_kontrol_sql) or die ("<span class=\"error\">User Ve Þifre Alan Fonksiyonda Hata Var</span>");
	$user_kontrol_rows = mysql_num_rows($user_kontrol_result);
	if ($user_kontrol_rows == 1) {
		$user_kontrol_arrays = mysql_fetch_row ($user_kontrol_result);
		return $user_kontrol_arrays;
	}
	mysql_free_result($user_kontrol_result);
}

function get_band ($string,$nedir) {
	// Band Seçimini Yapan Sql Statement
	$sql_string_band = "select * from bandnames where " . $nedir . " = '" . $string	 . "'";
	//echo "<br><span class=\"error\">" . $sql_string_band . "</span><br>";
	// Mysql Database'imize Gönderelim Sql'imizi ve sonuçlarý çekelim
	mysql_select_db("lld");
	$result_band = mysql_query ($sql_string_band) or die ("<span class=\"error\">Bu Query Sapýttý Be Caným (get_band)</span>");
	$num_rows_band = mysql_num_rows($result_band);
	// Kaç Satýr Var Acaba Bi Kontrol Et
	if ($num_rows_band > 0) {
		// Buraya Girdiðine Göre 0'dan Büyük
		$row_band = mysql_fetch_object ($result_band);
		// Datalarý Arraylýyoruz
		$bandid = $row_band->bandid;
		$bandname = $row_band->bandname;
		//Datalarý Deðiþkenlere Atadýk
		$band_info_return = array(
			"bandid"=>$bandid,
			"bandname"=>$bandname
			);
		// Deðiþkenleri Bir Arrayda Toplayalým
		return $band_info_return;
		// Süper Bi Þekilde Geri Döndürelim...
	}
	// Band Adý Bulunamadý Buradan NULL Olarak Geri Döner Bu Þekilde...
}

function get_lyric ($bandid,$string,$nedir,$countcont) {
	//Lyric Seçimini Yapan Sql Statement
	$sql_string_lyric = "select * from lyrics where bandname='" . $bandid ."' and " . $nedir . " = '" . $string . "'";
	//echo  "<br><span class=\"error\">" . $sql_string_lyric . "</span><br>";
	// Mysql Database'imize Gönderelim Sql'imizi ve sonuçlarý çekelim
	mysql_select_db("lld");
	$result_lyric = mysql_query ($sql_string_lyric) or die ("<span class=\"error\">Lyricleri alan Query Sapýttý Be Caným</span>");
	$num_rows_lyric = mysql_num_rows($result_lyric);
	// Kaç satýr çektiðimize bakalým bi
	if ($num_rows_lyric > 0) {
		// Buraya Girdiðine Göre 0'dan Büyük
		$row_lyric = mysql_fetch_object ($result_lyric);
		// Datalarý Arraylýyoruz
		$no = $row_lyric->no;
		$songname = $row_lyric->songname;
		$bandid = $row_lyric->bandname;
		$albumid = $row_lyric->albumname;
		$lyrics = $row_lyric->lyrics;
		$userid = $row_lyric->userid;
		$counter = $row_lyric->counter;
		// Bandid'sine Göre Adýnýda alalým...
		$band_info = get_band ($bandid,"bandid");
		//Albumid'sine göre albumun adýný alalým
		if ($albumid <> "") {
			$album_info_temp = get_album_info ($albumid);
			$albumname = $album_info_temp["albumname"];
		}
		// Datalarý Deðiþkenlere Atadýk
		if ($countcont != "sayma") {
			//echo "Update " . $countcont;
			//echo $count . "<br>";
			$sql_update = "UPDATE lyrics SET counter=counter+1 where bandname = " . $bandid . "  and songname = '" . $songname . "'";
			//	echo $sql_update;
			mysql_select_db("lld");
			$update_result = mysql_query ($sql_update);
			$target = "_blank";
		} else {
			//echo "Don't Update " . $countcont;
			$target = "_self";
		}
		$lyric_info_return = array(
			"no"=>$no,
			"songname"=>stripslashes($songname),
			"bandid"=>$bandid,
			"albumname"=>stripslashes($albumname),
			"albumid"=>$albumid,
			"lyrics"=>stripslashes($lyrics),
			"userid"=>stripslashes($userid),
			"counter"=>$counter,
			"bandname"=>stripslashes($band_info[bandname]),
			"target"=>$target
			);
		// Deðiþkenleri Bir Arrayda Toplayalým
		return $lyric_info_return;
		// Süper Bi Þekilde Geri Döndürelim...
	}
}

function get_lyricinfo_by_no($no) {
	//Numaraya göre sözleri alan sql
	$sql_string_lyric = "select * from lyrics where no = " . $no;
	//echo "<br><span class=\"error\">" . $sql_string_lyric . "</span><br>";
	// Mysql Database'imize Gönderelim Sql'imizi ve sonuçlarý çekelim
	mysql_select_db ("lld");
	$result_lyric = mysql_query ($sql_string_lyric) or die ("<span class=\"error\">Bu Query Sapýttý Be Caným (get_lyricinfo_by_no)</span>");
	$num_rows_lyric = mysql_num_rows($result_lyric);
	if ($num_rows_lyric > 0) {
		// Buraya Girdiðine Göre 0'dan Büyük
		$row_lyric = mysql_fetch_object ($result_lyric);
		// Datalarý Arraylýyoruz
		$no = $row_lyric->no;
		$songname = $row_lyric->songname;
		$bandid = $row_lyric->bandname;
		$albumnid = $row_lyric->albumname;
		$lyrics = $row_lyric->lyrics;
		$userid = $row_lyric->userid;
		$counter = $row_lyric->counter;
		// Bandid'sine Göre Adýnýda alalým...
		$band_info = get_band ($bandid,"bandid");
		//Albumid'sine göre albumun adýný alalým
		$album_info_temp = get_album_info ($albumnid);
		$albumname = $album_info_temp["albumname"];
		// Datalarý Deðiþkenlere Atadýk
		$lyric_info_return = array(
			"no"=>$no,
			"songname"=>$songname,
			"bandid"=>$bandid,
			"albumname"=>$albumname,
			"albumid"=>$albumnid,
			"lyrics"=>$lyrics,
			"counter"=>$counter,
			"userid"=>$userid,
			"bandname"=>$band_info[bandname],
			"target"=>$target
		);
		// Deðiþkenleri Bir Arrayda Toplayalým
		return $lyric_info_return;
		// Süper Bi Þekilde Geri Döndürelim...
	}
}

function get_album_info ($no) {
	//Numaraya göre albüm bilgisini alan sql
	$sql_album_info = "select * from albumnames where album_id = " . $no;
	//echo "<br><span class=\"error\">" . $sql_album_info . "</span><br>";
	//MySQL Database'imize gönderelim SQL'imizi ve sonuçlarý çekelim þeker þeker :)
	mysql_select_db("lld");
	$result_album_name = mysql_query ($sql_album_info) or die ("<span class=\"error\">Album bilgisini alan Query kafayý yedi (get_album_info)</span>");
	$num_rows_albumname = mysql_num_rows($result_album_name);
	//Datalarý Arraydan alalým dimi kuzuciðim
	if ($num_rows_albumname > 0) {
		$row_albumname = mysql_fetch_object ($result_album_name);
		$album_name = $row_albumname->albumname;
		$bandname = $row_albumname->bandname;
		//Gelen Datalarý Array'a Atalým
		$albuminfo_return = array (
		"album_id"=>$album_id,
		"albumname"=>$album_name,
		"bandname"=>$bandname
		);
		return $albuminfo_return;
	}
}

function get_album ($bandid,$albumname) {
	//Numaraya göre albüm bilgisini alan sql
	$sql_album_info = "select * from albumnames where bandname = " . $bandid . " and albumname = '" . $albumname . "'";
	//echo "<br><span class=\"error\">" . $sql_album_info . "</span><br>";
	//MySQL Database'imize gönderelim SQL'imizi ve sonuçlarý çekelim þeker þeker :)
	mysql_select_db("lld");
	$result_album_name = mysql_query ($sql_album_info) or die ("<span class=\"error\">Album bilgisini alan Query kafayý yedi (get_album)</span>");
	$num_rows_albumname = mysql_num_rows($result_album_name);
	//Datalarý Arraydan alalým dimi kuzuciðim
	if ($num_rows_albumname > 0) {
		$row_albumname = mysql_fetch_object ($result_album_name);
		$album_id = $row_albumname->album_id;
		$album_name = $row_albumname->albumname;
		$bandname = $row_albumname->bandname;
		//Gelen Datalarý Array'a Atalým
		$albuminfo_return = array (
		"album_id"=>$album_id,
		"albumname"=>$album_name,
		"bandname"=>$bandname
		);
		return $albuminfo_return;
	}
}

function add_band($bandname) {
	$sql_string_band_add = "insert into bandnames (bandname) values ('" . $bandname . "')";
	//echo "<br><span class=\"error\">" . $sql_string_band_add . "</span><br>";
	mysql_select_db("lld");
	mysql_query ($sql_string_band_add) or die ("<span class=\"error\">Band'ý Ekleyen Query Kafayý Yedi</span>");
}

function add_album($bandid,$albumname) {
	$sql_string_albumname_add = "insert into albumnames (bandname, albumname) values ('" . $bandid . "','" . $albumname . "')";
	//echo "<br><span class=\"error\">" . $sql_string_albumname_add . "</span><br>";
	mysql_select_db("lld");
	mysql_query ($sql_string_albumname_add) or die ("<span class=\"error\">Album adýný ekleyen query kafayý yedi</span>");
}

function add_lyric ($songname, $bandid, $albumid, $lyrics, $userid) {
	$sql_string = "INSERT INTO lyrics (songname, bandname, albumname, lyrics, userid, counter) VALUES ('" . $songname . "', " . $bandid . ", '" . $albumid . "', '" . $lyrics . "'," . $userid . ",1)";
	//echo "<br><span class=\"error\">" . $sql_string . "</span><br>";
	mysql_select_db("lld");
	mysql_query ($sql_string) or die ("<span class=\"error\">Lyricleri ekleyen query kafayý yedi</span>");
}

function baglanti_sayaci_artir ($userid) {
	$sql_baglanti_artirici = "Update users set baglanti_sayaci = baglanti_sayaci + 1 where userid = " . $userid;
	//echo "<br><span class=\"error\">" . $sql_baglanti_artirici . "</span><br>";
	mysql_select_db("lld");
	mysql_query ($sql_baglanti_artirici) or die ("<span class=\"error\">Baðlantýlarý Sayan Query Kafayý Yedi</span>");
}

function kontrol_et($test) {
	//echo "test - " . $test;
	$zaman_kont = preg_match_all("/\[[0-9]{2}:[0-9]{2}\]/i", $test, $bul);
	//echo $zaman_kont;
	if ($zaman_kont) {
    	//print "Zaman Var.";
		$zaman_sayisi = count ($bul[0]);
		//print_r($bul[0]);
		//echo "<br><span class=\"error\">" . $zaman_sayisi . "</span><br>";
		for ($i=1;$i<=$zaman_sayisi;$i++) {
			$pat_time = $bul[0][$i-1];
			$time[$i] = (((substr ($pat_time, 1, 2) * 60) + substr ($pat_time, 4, 2)) * 1000) - 500;
		}
		$test = substr($test, 7 * $zaman_sayisi);
		$donen_array = array($test, $time);
		//print_r($donen_array);
		return $donen_array;
	} else {
		$time = 9999999;
		$donen_array = array($test, $time);
		return $donen_array;
	}
}

function get_user_by_id($id) {
	//echo $kullanici_adi . "<br>" . $sifre;
	$user_kontrol_sql = "Select * from users where userid = " . $id;
	//echo $user_kontrol_sql . "<br>";
	mysql_select_db("lld");
	$user_kontrol_result = mysql_query($user_kontrol_sql) or die ("<span class=\"error\">User Ve Þifre Alan Fonksiyonda Hata Var</span>");
	$user_kontrol_rows = mysql_num_rows($user_kontrol_result);
	if ($user_kontrol_rows == 1) {
		$user_kontrol_arrays = mysql_fetch_row ($user_kontrol_result);
		return $user_kontrol_arrays;
	}
	mysql_free_result($user_kontrol_result);
}
?>
Return current item: Local Lyric Displayer