At the beginning I will add that I am just starting to write in PHP + mysqli. I was working on mysql all the time .
I created something like a CMS-based website , but everything was / is done in old, decrypted language . I have created two management files "driver_mysql and engine." Everything works as it should on older versions, but I have to move it to mysqli.
SO :
There are functions saved in driver_mysql.php, which I later use in the engine.php itself or in a smaller amount as I make a query.
How i should write 2 functions in mysqli . You probably write that I should learn first and then write . If there was a nice person and could write me how to do these two functions, I would be grateful. I would correct the rest based on this, because I don't know how to connect by myself, because you need 2 arguments
I have set in config.php : $db_host , $user_login , $user_password , $db_name
CODE + FUNCTIONS :
driver_mysql.php
function db_connect(
$db_host,
$user_login,
$user_password
)
{
if (
mysql_connect (
$db_host,
$user_login,
$user_password
)
)
{
return TRUE;
}
else
{
return FALSE;
}
}
function SelectDB($db_name)
{
if(mysql_select_db($db_name))
{
return TRUE;
}
else
{
return FALSE
}
}
Should I do smth like that ? :
function db_connect($mysqli = mysqli_connect($db_host,$user_login,$user_password)
{
if (
mysqli_connect (
$db_host,
$user_login,
$user_password
)
)
{
return TRUE;
}
else
{
return FALSE;
}
}
AND
function SELECTDB($db_name)
{
$link = mysqli_connect($db_host,$user_login,$user_password)
if(mysqli_select_db($link, $db_name)
{ return TRUE; } else { return FALSE; } }
I'll add if in engine.php I have
$connect = db_connect(
$db_host,
$user_login,
$user_password);
if($connect == FALSE) { echo 'ERROR MESSAGE'; exit(); }
AND FOR DB SELECT
$db_selecting = selectDB($db_name);
if($db_selecting == FALSE) { echo 'ERROR MESSAGE'; exit(); }
Thank you for any help !!!!