📜  php pdo 获取由 href 选择的 id - PHP 代码示例

📅  最后修改于: 2022-03-11 14:53:44.690000             🧑  作者: Mango

代码示例1
 PDO::ERRMODE_EXCEPTION,        // enable PDO errors
    PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,   // fetch associative arrays by default
    PDO::ATTR_EMULATE_PREPARES => false,                // Use native prepared statements
];
//                      You should always specify charset VVVVV
$pdo = new PDO("mysql:host=$host;dbname=$dbname;charset=utf8mb4", $username, $password, $options);

// Prepare and execute SQL passing in the value of $id  // Verificar o pedido "GET" id param
  $id = $_GET['id'];
  
  // Preparar e executar a passagem SQL no valor de $id
  $query = $pdo->prepare('SELECT * FROM nametable WHERE id = ? ORDER BY nameselect DESC');
  $query->execute([$id]);
?>
  
   
     $row  ['namerow']