Help me to modify my code according to new standards and API.
I have create a file like.php
: I have created a function for getting result in return with ternary operator
function article_exists($article_id)
{
$article_id =(int)$article_id;
return (mysql_result("SELECT COUNT(article_id) from articles where article_id= $article_id", 0)==0)?false:true;
}
I want to use the code with mysqli_result and i m calling it from another page I need to get print exist when my page index.php runs
index.php
if(article_exists(1)===true)
{
echo "exist";
}
you have to change the script like this
function article_exists($article_id){
$article_id =(int)$article_id;
return (mysqli_query($connect,"SELECT COUNT(article_id) from articles where article_id= $article_id", 0)==0)?false:true;
}
## Connection File ##
$connect= mysqli_connect("localhost","my_user","my_password","my_db");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}