
Bilgilerim doğru olmasına rağmen,izinleri aktif olmasına rağmen bu hatayı alıyorum.
Hata nedir?
<?php
require 'vendor/autoload.php'; // Google Cloud Translate API kütüphanesi
use Google\Cloud\Translate\V2\TranslateClient;
// MySQL veritabanı bağlantısı için gerekli bilgiler
$servername = "localhost"; // Veritabanı sunucusu (genellikle localhost)
$username = "gizli"; // MySQL kullanıcı adı
$password = "gizli"; // MySQL şifresi
$database = "gizli"; // Kullanmak istediğiniz veritabanı adı
// Google Cloud Translate API anahtarı
$googleApiKey = "gizli"; // API anahtarınızı buraya ekleyin
// MySQL veritabanına bağlanma
$conn = new mysqli($servername, $username, $password, $database);
// Bağlantıyı kontrol et
if ($conn->connect_error) {
die("Bağlantı hatası: " . $conn->connect_error);
}
// "services" tablosundan ilk 5 veriyi sorgulama
$sql = "SELECT id, gizli FROM services LIMIT 5"; // Sadece ilk 5 satırı sorgula
$result = $conn->query($sql);
if ($result->num_rows > 0) {
// Google Çeviri API'sına erişim sağlama
$translate = new TranslateClient([
'key' => $googleApiKey,
]);
// Veritabanından gelen verileri işleme
while ($row = $result->fetch_assoc()) {
$serviceId = $row["id"];
$serviceName = $row["service_name"];
// Service adını algıla ve Türkçeye çevir
$translation = $translate->translate($serviceName, [
'target' => 'tr', // Türkçe hedef dil
]);
// Veriyi güncelle
$updateSql = "UPDATE services SET service_name = '" . $translation['text'] . "' WHERE id = " . $serviceId;
$conn->query($updateSql);
}
} else {
echo "Tabloda hiç veri yok.";
}
// Veritabanı bağlantısını kapatma
$conn->close();
?>