sql >> Database >  >> RDS >> Mysql

Gegevens ophalen uit mysql met php

// Initializing connection data.
$host_db = 'localhost';
$name_db = 'article_db';
$user_db = 'username';
$pass_db = 'password';

try {
  // Connecting using the PDO object.
  $connection = new PDO("mysql:host=$host_db; dbname=$name_db", $user_db, $pass_db);

  // Setting the query and runnin it...
  $sql = "SELECT * FROM `article` WHERE `category` = 5 ORDER BY 3";
  $result = $connection->query($sql);

  // Iterating over the data and printing it.
  foreach($result as $row) {
      echo $row['id']. ' - '. $row['name']. ' - '. $row['category']. ' - '. $row['editor']. '<br />';
  }
  // Closing the connection.
  $connection = null;
}
// Catching it if something went wrong.
catch(PDOException $e) {
  echo $e->getMessage();
}


  1. Breekt MySQL de norm door kolommen te selecteren die geen deel uitmaken van de group by-clausule?

  2. PHP paginering klasse

  3. Mysql-waarde splitsen in een onbekend aantal delen

  4. DMV ( Dynamic Management View ) en DMF ( Dynamic Management Function ) gebruiken | Problemen met SQL Server-prestaties oplossen -4