There are many files [ file1.php, file2.php ] in our project & i wrote database connection code in many files instead of single file [ database.php ] , is there any problem with that ?
if it is wrong than please help me what code i need to change in file1.php to connect to database.php
Below 2 lines i used in file1.php
$con=mysqli_connect('localhost', 'root', 'gfgf', 'g');
if ($result=mysqli_query($con,$sql))
Instead of above 2 lines, is it correct to use below 2 lines ?
require_once("database.php");
$db_handle = new DBController();
file1.php
<?php
require_once("database.php");
$db_handle = new DBController();
$con=mysqli_connect('localhost', 'root', 'gfgf', 'g');
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$todaydate=date('Y-m-d');
$sql="SELECT * FROM orders WHERE importdate >= NOW() - INTERVAL 1 DAY";
if ($result=mysqli_query($con,$sql))
{
$rowcount=mysqli_num_rows($result);
printf("Uploaded - %d rows.\n",$rowcount);
// Free result set
mysqli_free_result($result);
}
mysqli_close($con);
?>
require_once("database.php"); $db_handle = new DBController();
its not give correct rows of table.... \$\endgroup\$