Mysql
 sql >> Baza danych >  >> RDS >> Mysql

Pobierz dane z mysql za pomocą 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. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Wyjątek hibernacji w zapytaniu łączenia krzyżowego MySQL

  2. Zalety korzystania z widoków w MySQL

  3. Jak debugować zapytanie w extbase?

  4. Źródło danych MySQL nie pojawia się w Visual Studio

  5. CodeIgniter Active Record wstawia się z jednej tabeli do drugiej