• 29-11-2022, 22:10:04
    #1
    Selamlar,

    Kod parçaçığında aşağıdaki gibi bir hata alıyorum.
    Çözümü için yardımcı olabilir misiniz ?

    Hata kodu (log'a yansıyan) : PHP Parse error: syntax error, unexpected '=>' (T_DOUBLE_ARROW), expecting ']' in /home/2021/public_html/v2/orm/addJsonTable.php on line 43

    Hatayı aldığım kodun tamamı aşağıda - 43. Satır burası: 'ID' => $item['ID'],

    <?php
    ini_set('error_reporting', E_ALL);
    ini_set('display_errors', true);
    set_time_limit(0);
    header("Access-Control-Allow-Origin: http://127.0.0.1:8887");
    header("Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE");
    header("Access-Control-Allow-Credentials: true");
    header('Content-Type: application/json');
    require_once "idiorm.php";
    require_once "methods.php";
    initDB();
    
    $ID = isset($_GET['id']) ? $_GET['id'] : 0;
    if ($ID) {
    
        $hasItem = ORM::for_table('json_table')->where('ID', $ID)->find_one();
        if ($hasItem) {
            ORM::raw_execute("delete from json_table where ID = $ID");
        } 
        
        
    
        $phone = ORM::for_table('exportview')->where('ID', $ID)->find_array();
    
        $phone = array_map(exportMeta, $phone);
        $phone = array_map(exportTerms, $phone);
        $phone = array_map(exportMedia, $phone);
        foreach ($phone as $ikey => $item) {
            $phone[$ikey]['media']         = $item['media_ids'] ? array_map(exportMeta, $item['media']) : [];
            $phone[$ikey]['media']         = $item['media_ids'] ? array_combine(array_column($phone[$ikey]['media'], 'ID'), array_column($phone[$ikey]['media'], 'guid')) : [];
            $phone[$ikey]['insert_time']   = strtotime($item['post_date_gmt']);
            $phone[$ikey]['image']         = $item['meta']['resim_url'] ?: $phone[$ikey]['media'][$item['meta']['_thumbnail_id']] ?: null;
            $phone[$ikey]['primary_image'] = $phone[$ikey]['media'][$item['meta']['_thumbnail_id']] ?: null;
        }
    
        foreach ($phone as $key => $item) {
            if ($key < 1000000) {
                $item['meta']['term_ids']  = $item['term_ids'];
                $item['meta']['media_ids'] = $item['media_ids'];
    
                ORM::raw_execute("INSERT INTO `json_table` (ID, title, name, type, image, primary_image, meta, media, insert_time) VALUES(:ID, :title, :name, :type, :image, :primary_image, :meta, :media, :insert_time);"
                    [
                        'ID'            => $item['ID'],
                        'title'         => $item['post_title'],
                        'name'          => $item['post_name'],
                        'type'          => $item['post_type'],
                        'image'         => $item['image'],
                        'primary_image' => $item['primary_image'],
                        'meta'          => json_encode($item['meta']),
                        'media'         => json_encode($item['media']),
                        'insert_time'   => $item['insert_time'],
                    ]
                );
            }
        }
      ORM::raw_execute("update json_table set primary_image = concat('/wp-content/uploads/', primary_image) where (primary_image  not like '%http%' and primary_image  not like '%wp-content%');");
      
        echo 1;
    
    } else {
        echo 0;
    }
    Yardımcı olabilirseniz mutlu olurum.
    Teşekkürler.
  • 29-11-2022, 22:21:06
    #2
    "INSERT INTO `json_table` (ID, title, name, type, image, primary_image, meta, media, insert_time) VALUES(:ID, :title, :name, :type, :image, :primary_image, :meta, :media, :insert_time);"
    Bu kod bloğundan sonra virgul (,) eklemeniz gerekiyor.

    `raw_execute` iki farklı değer (`$query, $parameters`) alıyor ve değerler birbirinden "," iler ayrılmalıdır.
  • 29-11-2022, 22:26:01
    #3
    Virgül eklersem çok daha fazla log'da hata veriyor.

    [29-Nov-2022 19:23:33 UTC] PHP Warning:  PDOStatement::execute(): SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'json_table where ID = 403425' at line 1 in /home/siteadi/public_html/v2/orm/idiorm.php on line 505
    [29-Nov-2022 19:23:33 UTC] PHP Warning:  Use of undefined constant exportMeta - assumed 'exportMeta' (this will throw an Error in a future version of PHP) in /home/siteadi/public_html/v2/orm/addJsonTable.php on line 25
    [29-Nov-2022 19:23:33 UTC] PHP Warning:  Use of undefined constant unserializeFunc - assumed 'unserializeFunc' (this will throw an Error in a future version of PHP) in /home/siteadi/public_html/v2/orm/methods.php on line 57
    [29-Nov-2022 19:23:33 UTC] PHP Warning:  Use of undefined constant exportTerms - assumed 'exportTerms' (this will throw an Error in a future version of PHP) in /home/siteadi/public_html/v2/orm/addJsonTable.php on line 26
    [29-Nov-2022 19:23:33 UTC] PHP Warning:  Use of undefined constant exportMedia - assumed 'exportMedia' (this will throw an Error in a future version of PHP) in /home/siteadi/public_html/v2/orm/addJsonTable.php on line 27
    [29-Nov-2022 19:23:33 UTC] PHP Warning:  Use of undefined constant exportMeta - assumed 'exportMeta' (this will throw an Error in a future version of PHP) in /home/siteadi/public_html/v2/orm/addJsonTable.php on line 29
    [29-Nov-2022 19:23:33 UTC] PHP Warning:  Use of undefined constant unserializeFunc - assumed 'unserializeFunc' (this will throw an Error in a future version of PHP) in /home/siteadi/public_html/v2/orm/methods.php on line 57
    [29-Nov-2022 19:23:33 UTC] PHP Warning:  Use of undefined constant unserializeFunc - assumed 'unserializeFunc' (this will throw an Error in a future version of PHP) in /home/siteadi/public_html/v2/orm/methods.php on line 57
    [29-Nov-2022 19:23:33 UTC] PHP Warning:  Use of undefined constant unserializeFunc - assumed 'unserializeFunc' (this will throw an Error in a future version of PHP) in /home/siteadi/public_html/v2/orm/methods.php on line 57
    [29-Nov-2022 19:23:33 UTC] PHP Warning:  Use of undefined constant unserializeFunc - assumed 'unserializeFunc' (this will throw an Error in a future version of PHP) in /home/siteadi/public_html/v2/orm/methods.php on line 57
    [29-Nov-2022 19:23:33 UTC] PHP Warning:  Use of undefined constant unserializeFunc - assumed 'unserializeFunc' (this will throw an Error in a future version of PHP) in /home/siteadi/public_html/v2/orm/methods.php on line 57
    [29-Nov-2022 19:23:33 UTC] PHP Warning:  Use of undefined constant unserializeFunc - assumed 'unserializeFunc' (this will throw an Error in a future version of PHP) in /home/siteadi/public_html/v2/orm/methods.php on line 57
    [29-Nov-2022 19:23:33 UTC] PHP Warning:  Use of undefined constant unserializeFunc - assumed 'unserializeFunc' (this will throw an Error in a future version of PHP) in /home/siteadi/public_html/v2/orm/methods.php on line 57
    [29-Nov-2022 19:23:33 UTC] PHP Warning:  Use of undefined constant unserializeFunc - assumed 'unserializeFunc' (this will throw an Error in a future version of PHP) in /home/siteadi/public_html/v2/orm/methods.php on line 57
    [29-Nov-2022 19:23:33 UTC] PHP Warning:  Use of undefined constant unserializeFunc - assumed 'unserializeFunc' (this will throw an Error in a future version of PHP) in /home/siteadi/public_html/v2/orm/methods.php on line 57
    [29-Nov-2022 19:23:33 UTC] PHP Warning:  PDOStatement::execute(): SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'set primary_image = concat('/wp-content/uploads/', primary_image) where (primary' at line 1 in /home/siteadi/public_html/v2/orm/idiorm.php on line 505
    [29-Nov-2022 19:23:36 UTC] PHP Warning:  PDOStatement::execute(): SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'json_table where ID = 403425' at line 1 in /home/siteadi/public_html/v2/orm/idiorm.php on line 505
    [29-Nov-2022 19:23:36 UTC] PHP Warning:  Use of undefined constant exportMeta - assumed 'exportMeta' (this will throw an Error in a future version of PHP) in /home/siteadi/public_html/v2/orm/addJsonTable.php on line 25
    [29-Nov-2022 19:23:36 UTC] PHP Warning:  Use of undefined constant unserializeFunc - assumed 'unserializeFunc' (this will throw an Error in a future version of PHP) in /home/siteadi/public_html/v2/orm/methods.php on line 57
    [29-Nov-2022 19:23:36 UTC] PHP Warning:  Use of undefined constant exportTerms - assumed 'exportTerms' (this will throw an Error in a future version of PHP) in /home/siteadi/public_html/v2/orm/addJsonTable.php on line 26
    [29-Nov-2022 19:23:36 UTC] PHP Warning:  Use of undefined constant exportMedia - assumed 'exportMedia' (this will throw an Error in a future version of PHP) in /home/siteadi/public_html/v2/orm/addJsonTable.php on line 27
    [29-Nov-2022 19:23:36 UTC] PHP Warning:  Use of undefined constant exportMeta - assumed 'exportMeta' (this will throw an Error in a future version of PHP) in /home/siteadi/public_html/v2/orm/addJsonTable.php on line 29
    [29-Nov-2022 19:23:36 UTC] PHP Warning:  Use of undefined constant unserializeFunc - assumed 'unserializeFunc' (this will throw an Error in a future version of PHP) in /home/siteadi/public_html/v2/orm/methods.php on line 57
    [29-Nov-2022 19:23:36 UTC] PHP Warning:  Use of undefined constant unserializeFunc - assumed 'unserializeFunc' (this will throw an Error in a future version of PHP) in /home/siteadi/public_html/v2/orm/methods.php on line 57
    [29-Nov-2022 19:23:36 UTC] PHP Warning:  Use of undefined constant unserializeFunc - assumed 'unserializeFunc' (this will throw an Error in a future version of PHP) in /home/siteadi/public_html/v2/orm/methods.php on line 57
    [29-Nov-2022 19:23:36 UTC] PHP Warning:  Use of undefined constant unserializeFunc - assumed 'unserializeFunc' (this will throw an Error in a future version of PHP) in /home/siteadi/public_html/v2/orm/methods.php on line 57
    [29-Nov-2022 19:23:36 UTC] PHP Warning:  Use of undefined constant unserializeFunc - assumed 'unserializeFunc' (this will throw an Error in a future version of PHP) in /home/siteadi/public_html/v2/orm/methods.php on line 57
    [29-Nov-2022 19:23:36 UTC] PHP Warning:  Use of undefined constant unserializeFunc - assumed 'unserializeFunc' (this will throw an Error in a future version of PHP) in /home/siteadi/public_html/v2/orm/methods.php on line 57
    [29-Nov-2022 19:23:36 UTC] PHP Warning:  Use of undefined constant unserializeFunc - assumed 'unserializeFunc' (this will throw an Error in a future version of PHP) in /home/siteadi/public_html/v2/orm/methods.php on line 57
    [29-Nov-2022 19:23:36 UTC] PHP Warning:  Use of undefined constant unserializeFunc - assumed 'unserializeFunc' (this will throw an Error in a future version of PHP) in /home/siteadi/public_html/v2/orm/methods.php on line 57
    [29-Nov-2022 19:23:36 UTC] PHP Warning:  Use of undefined constant unserializeFunc - assumed 'unserializeFunc' (this will throw an Error in a future version of PHP) in /home/siteadi/public_html/v2/orm/methods.php on line 57
    [29-Nov-2022 19:23:36 UTC] PHP Warning:  PDOStatement::execute(): SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'set primary_image = concat('/wp-content/uploads/', primary_image) where (primary' at line 1 in /home/siteadi/public_html/v2/orm/idiorm.php on line 505
    methods.php on line 57 ise burası. ($item['meta'] = array_map(unserializeFunc, $item['meta'])

    function exportMeta($item)
    {
        $item['meta'] = ORM::for_table('wp_postmeta')->where('post_id', $item['ID'])->where_not_like('meta_value', 'field_%')->find_array();
        $item['meta'] = array_map(unserializeFunc, $item['meta']);
        $item['meta'] = array_combine(array_column($item['meta'], 'meta_key'), array_column($item['meta'], 'meta_value'));
        $item['meta'] = array_filter($item['meta']);
        if ($item['post_type'] == 'attachment' && isset($item['meta']) && $item['meta']['_wp_attached_file']) {
            $item['guid'] = $item['meta']['_wp_attached_file'];
        }
    
        return $item;
    }