Mysql
 sql >> Teknologi Basis Data >  >> RDS >> Mysql

php pdo menyisipkan kueri

Anda hampir sampai, ini adalah versi yang disederhanakan:

<?php

$sql = "insert into `users` (`username`,`password`) values (?, aes_encrypt(?, ?))";
$stmt = $this->pdo->prepare($sql);

// Do not use associative array
// Just set values in the order of the question marks in $sql
// $fill_array[0] = $_POST['username']  gets assigned to first ? mark
// $fill_array[1] = $_POST['password']  gets assigned to second ? mark
// $fill_array[2] = $DBKey              gets assigned to third ? mark

$fill_array = array($_POST['username'], $_POST['password'], $DBKey); // Three values for 3 question marks

// Put your array of values into the execute
// MySQL will do all the escaping for you
// Your SQL will be compiled by MySQL itself (not PHP) and render something like this:
// insert into `users` (`username`,`password`) values ('a_username', aes_encrypt('my_password', 'SupersecretDBKey45368857'))
// If any single quotes, backslashes, double-dashes, etc are encountered then they get handled automatically
$stmt->execute($fill_array); // Returns boolean TRUE/FALSE

// Errors?
echo $stmt->errorCode().'<br><br>'; // Five zeros are good like this 00000 but HY001 is a common error

// How many inserted?
echo $stmt->rowCount();

?>


  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. mysql:Bagaimana cara INNER JOIN sebuah tabel tetapi batasi bergabung dengan 1 hasil dengan suara atau hitungan tertinggi?

  2. Kesalahan:Batas waktu tidak aktif jabat tangan di Node.js v6.9.1 dan MySQL

  3. Bagaimana saya bisa mengulangi set hasil MySQL?

  4. Temukan baris yang paling cocok di MySQL (InnoDB)

  5. Bagaimana cara menambahkan tanggal ke nama tabel MySQL?