Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

How to use MySQL SELECT Statement in PHP

<?php
$driver = 'mysql';
$database = "dbname=CODINGGROUND";
$dsn = "$driver:host=localhost;$database";

$username = 'root';
$password = 'root';

try {
   $conn = new PDO($dsn, $username, $password);
   echo "Database CODINGGROUND Connected\n";
}catch(PDOException $e){
   echo $e->getMessage();
}
$sql = 'SELECT  * FROM users';
$stmt = $conn->prepare($sql);
$stmt->execute();

while($row = $stmt->fetch(PDO::FETCH_ASSOC)){
  foreach($row as $value)
  {
    echo sprintf("%s, ", $value);
  }
  echo "\n";
}
?>

test

<?php
$driver = 'mysql';
$database = "dbname=CODINGGROUND";
$dsn = "$driver:host=localhost;$database";

$username = 'root';
$password = 'root';

try {
   $conn = new PDO($dsn, $username, $password);
   echo "Database CODINGGROUND Connected\n";
}catch(PDOException $e){
   echo $e->getMessage();
}
$sql = 'SELECT  * FROM users';
$stmt = $conn->prepare($sql);
$stmt->execute();

while($row = $stmt->fetch(PDO::FETCH_ASSOC)){
  foreach($row as $value)
  {
    echo sprintf("%s, ", $value);
  }
  echo "\n";
}
?>

create db and tables

<?php
class Car {
    private $color;
    public function getColor() {
        $col_car = $this->color = 'red';
        print_r($this);
        return $col_car;
    }
}
$car = new Car();
echo "Car1 is " . $car->getColor();
//echo "<br>";

differenze public-private

Unable to open file!