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

Ubah fungsi ke PDO

Coba ini:

$conn = new PDO('mysql:host=localhost;dbname=dbname', 'root', 'password');
function stream($IdPhoto=0) {
global $conn;

if ($IdPhoto==0) {

    // load the last 300 photos
    $stmt = $conn->prepare("SELECT IdPhoto, device_token, IdUser FROM photos ORDER BY IdPhoto DESC LIMIT 300 ");
    $stmt->execute();
    $result = $stmt->fetch(PDO::FETCH_ASSOC);

} else {

//This is the statement i need to call explicitly via PDO

    //do the same as above, but just for the photo with the given id
    $stmt = $conn->prepare("SELECT p.IdPhoto, p.device_token, p.IdUser FROM photos p JOIN login l ON (l.IdUser = p.IdUser) WHERE p.IdPhoto= :idphoto ");
    $stmt->execute([':idphoto' => $IdPhoto]);
    $result = $stmt->fetch(PDO::FETCH_ASSOC);

}

if (!$stmt->errorInfo()[0]) {
    // if no error occured, print out the JSON data of the 
    // fetched photo data
    print json_encode($result);
} else {
    //there was an error, print out to the iPhone app
    errorJson('Photo stream is broken');
}
}



  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Kesalahan Kerangka Entitas MySQL - Penyedia toko yang ditentukan tidak dapat ditemukan dalam konfigurasi, atau tidak valid

  2. MySqlCommand().ExecuteReader().GetString() tidak berfungsi

  3. PHP PDO vs mysql_connect biasa

  4. Stempel waktu dengan presisi milidetik:Bagaimana cara menyimpannya di MySQL

  5. tabel mysqldump tanpa membuang kunci utama