<?php

if (function_exists('mysqli_connect') && !function_exists('mysql_pconnect'))
{
	if (!defined('MYSQL_ASSOC')) define("MYSQL_ASSOC","MYSQL_ASSOC");

	function mysql_pconnect($server,$login,$password)
	{
		global $mydatabase;
	
		$db=mysqli_connect($server, $login, $password, $mydatabase);
		
		if (!$db)
		{
		  echo("Could not connect : ");
		  echo(mysqli_connect_error());
		  echo("<br>");
		}
		if (!mysqli_set_charset($db, "utf8"))
		{
			printf("Erreur lors du chargement du jeu de caractères utf8 : %s\n", mysqli_error($db));
			exit();
		}
		return $db;
	}

	function mysql_select_db($db)
	{
		return TRUE;
	}

	function mysql_query($sql_query)
	{
		global $dbh;
	
		return mysqli_query( $dbh, $sql_query );
	}
	
	function mysql_num_fields($result)
	{
		return mysqli_num_fields( $result);
	}

	function mysql_num_rows($result)
	{
		return mysqli_num_rows( $result);
	}
	
	function mysql_fetch_row($result)
	{
		return mysqli_fetch_row($result);
	}

	function mysql_fetch_array($result, $param="")
	{
		if($param==MYSQL_ASSOC)
		{
			return mysqli_fetch_assoc($result);
		}
		else
		{
			return mysqli_fetch_array($result);
		}
	}
	
	function mysql_close()
	{
		global $dbh;
	
		return mysqli_close($dbh);
	}
}	

function mysql_die($error = "")
{
	global $strError, $strMySQLSaid, $strBack, $sql_query, $dbh;

	echo "<HTML><b> $strError </b>";
	if(isset($sql_query) && !empty($sql_query))
	{
		display_lng_text("ERR_MYSQL");
		echo " : <b>$sql_query</b>";
	}
	if(!empty($error))
	{
		display_lng_text("ERR_MYSQL");
		echo " : ".$strMySQLSaid.$error;
	}
	if (function_exists('mysqli_error') && !function_exists('mysql_error'))
	{
		echo " : ".$strMySQLSaid.mysqli_error($dbh);
	}
	else
	{
		echo " : ".$strMySQLSaid.mysql_error();
	}
	echo "<p>";
}

$dbh=mysql_pconnect($server,$login,$password);
$db=$mydatabase;
if(mysql_select_db($db)==FALSE)
{
	if($mydatabase=="")
	{
		$mydatabase="test";
	}
	$dbh=mysql_connect();
	$db=$mydatabase;
	if(mysql_select_db($db)==FALSE)
	{
		if($server=="" && $login=="" && $password=="" && $mydatabase=="")
		{
			display_lng_text("LIB_INC_NO_PARAM");
			exit;
		}
		else
		{
			display_lng_text("LIB_INC_BAD_PARAM");
			exit;
		}
	}
}
mysql_query("SET SESSION character_set_results = 'UTF8'");
?>