• 21-09-2020, 02:26:17
    #1
    Bir php dosyası hazırladık.

    1- Veritabanına bağlanıyor.
    2- Belirli bir kullanıcıyı seçiyor.
    3- Onlara bildirim gönderiyor.

    Sistem Php 7.2'de kusursuz çalışıyor.

    Ancak PHP 7.3'te çalışmıyor. Veritabanına bağlanıyor, kullanıcıları seçemiyor.

    Sorun şurayla ilişkili = $sql = "select isadmin, pushtoken from users where isadmin=1"; (sorunu göstersin diye print yaptım 7.3 de onu da göstermiyor)

    Kodu paylaşıyorum. Biri yardım edebilir mi?

    <?php
    
    
    
    
    
    $targetHost="xxxxx";
    
    
    
    
    $servername = "localhost";
    $username = "xxx";
    $password = "xxxx";
    $dbname = "xxxxx";
    
    
    
    
    $conn = mysqli_connect($servername, $username, $password, $dbname);
    
    if (!$conn) {
    die("Database connection failed: " . $conn->connect_error);
    }
    echo "Database connected successfully" . "<br>";
    
    function sendGCM($token) {
    
    $data = [
    "to" => $token,
    "notification" =>
    [
    "title" => '🚨 COMPUTER CLOSED 🚨',
    "body" => "Open the computer",
    'default_sound' => true,
    'sound' => "res/raw/notify.mp3",
    'priority' => 'high'
    ],
    ];
    $dataString = json_encode($data);
    
    $headers = [
    'Authorization: key=' . 'xxxxxx',
    'Content-Type: application/json',
    ];
    
    $ch = curl_init();
    
    curl_setopt($ch, CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send');
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $dataString);
    
    curl_exec($ch);
    }
    
    exec("ping -c 4 " . $targetHost, $output, $res);
    print_r($output);
    if ($res == 0) {
    echo "Successfully got response from the server";
    }
    
    
    else{
    $sql = "select isadmin, pushtoken from users where isadmin=1";
    $result = mysqli_query($conn,$sql);
    print_r($result);
    if(mysqli_num_rows($result) > 0){
    while($row = $result->fetch_assoc()) {
    sendGCM($row["pushtoken"]);
    echo "Notification sent!";
    }
    } else {
    echo "0 admins found in database";
    }
    }
    ?>
  • 21-09-2020, 02:27:12
    #2
    Üyeliği durduruldu
    PHP Ayarlarından mysqli aktif edin? veya aktif mi?
  • 21-09-2020, 02:30:29
    #3
    Mysqli kullanan kalmış mı?

    PDO kullanmanız sorunu çözebilir.
  • 21-09-2020, 02:33:04
    #4
    mymajans adlı üyeden alıntı: mesajı görüntüle
    PHP Ayarlarından mysqli aktif edin? veya aktif mi?
    üst satırlardaki kodda connect mysqli bağlanıyor sorun kullanıcıyı seçemiyor
  • 21-09-2020, 09:19:57
    #5
    ne hatası veriyor , hata kodlarını aktif edip burada paylaşır mısınız ?

    Bu arada isadmin integer tipinde mi ? değil ise '1' olarak deneyin.
  • 21-09-2020, 12:29:30
    #6
    FaTe adlı üyeden alıntı: mesajı görüntüle
    ne hatası veriyor , hata kodlarını aktif edip burada paylaşır mısınız ?

    Bu arada isadmin integer tipinde mi ? değil ise '1' olarak deneyin.

    '1' kurtarmadı hocam. ---- 0 admins found in database ---- hatasını veriyor. Ulaşamayınca veren hatayı

    print_r($result); yaptım sonuç dökmüyor