Database connection and SELECT

129 views Asked by At

I tried to connect to the database and echo information but it's don't work. Can someone help me with this? I connect to database in header.php file and try to use it in index.html where I use require_once header.php.

<?php
$hostname = 'localhost';
$user = 'username';
$pass = '123';
$database = 'name';

$db_connection = new PDO( "mysql:host=" . $hostname . ";dbname=" . $database, $user, $pass );

$totalSpace = $db_connection->query( "SELECT SUM(file_server.totalSpaceUsed) FROM file_server" );
$totalRegisteredUsers = $db_connection->query( "SELECT COUNT(1) AS total FROM users WHERE status='active'" );
$totalDownloads = $db_connection->query( "SELECT SUM(visits) AS total FROM file" );
?>

When I trying to echo I don't get anything.

<h2 class="mb-0 mt-3 display-4 text-white"><span class="counter-value" data-count="50"><?php echo $totalRegisteredUsers; ?></span></h2>
0

There are 0 answers