I upgraded codes of a php file upload and management script from PHP 5.4 to PHP 7.
It works now,
There are many functions at my functions.php file
it was giving some errors like;
Warning: mysqli_error() expects parameter 1 to be mysqli, null given in
Warning: mysqli_fetch_assoc expects parameter 1 to be mysqli, null given in
for every mysqli related codes for ever function inside of functions.php file.
to solve this problem, I put include('dbconnect.php'); to inside of every function {} as you can see at below sample codes.
Now script works but it is not normal because there are many include('dbconnect.php'); lines at functions.php file.
How can i solve this problem ?
Is there any simpler and better way to get rid of above errors and to put only one include('dbconnect.php'); to my php file.?
Thanks,
<?php
//GET USERNAME BY USER ID
function getUser($userID){
include('dbconnect.php');
$sqll="SELECT id,username FROM users WHERE id='".$userID."'";
$result1=mysqli_query($link,$sqll);
$row11=mysqli_fetch_assoc($result1);
$processor=$row11["username"];
return $processor;
}
function getExtensions(){
include('dbconnect.php');
$processor = array();
$sqll="SELECT * FROM extensions ORDER BY name ASC";
$result1=mysqli_query($link,$sqll);
while($row11=mysqli_fetch_assoc($result1)){
$processor[]=$row11["name"];
}
return $processor;
}
function getCommentCount($fileID){
include('dbconnect.php');
$sqll="SELECT COUNT(id) as countme FROM messages WHERE fileID='".$fileID."'";
$result1=mysqli_query($link,$sqll);
$row11=mysqli_fetch_assoc($result1);
return $row11["countme"];
}
function getUploadDir($user){
include('dbconnect.php');
$sqll="SELECT id,upload_dir FROM users WHERE id='".$user."'";
$result1=mysqli_query($link,$sqll);
$row11=mysqli_fetch_assoc($result1);
return $row11["upload_dir"];
}
function send_mail($subject="Notification",$message="") {
include('dbconnect.php');
$upload_notify_email = getSystemMail();
$from = 'AdvancedFileManager@'.$_SERVER['HTTP_HOST'];
$return_path = '-f '.$from ;
mail($upload_notify_email,$subject,$message,"From: $from\nX-Mailer: PHP/ . $phpversion()");
}
..................
?>