K
K
Ko12015-12-19 23:40:15
PHP
Ko1, 2015-12-19 23:40:15

How to add Bitrix ORM data to the table?

Hello everyone, there is a table in the database

use Bitrix\Main\Entity;
class MeasurmentTable extends Entity\DataManager{

    public static function getFilePath()
    {
        return __FILE__;
    }

    public static function getTableName()
    {
        return 'arc_measurment';
    }

    public static function getMap()
    {
        return array(
            'id' => array(
                'data_type' => 'integer',
                'primary' => true,
                'autocomplete' => true,
            ),
            'pid' => array(
                'data_type' => 'integer'
            ),
            'section' => array(
                'data_type' => 'integer'
            ),
            'has_picture' => array(
                'data_type' => 'integer'
            ),
            'position' => array(
                'data_type' => 'integer'
            ),
            'catalog_views' => array(
                'data_type' => 'integer'
            ),
            'detail' => array(
                'data_type' => 'integer'
            ),
            'basket_count' => array(
                'data_type' => 'integer'
            ),
            'available' => array(
                'data_type' => 'integer'
            ),
            'price' => array(
                'data_type' => 'integer'
            ),
            'buy_count' => array(
                'data_type' => 'integer'
            ),
            'has_discount' => array(
                'data_type' => 'integer'
            ),
            'addition_time' => array(
                'data_type' => 'integer'
            ),
            'has_detail_text' => array(
                'data_type' => 'integer'
            )
        );
    }

    public static function CreateTable()
    {
        $sql_query = '
            CREATE TABLE IF NOT EXISTS ' . self::getTableName() . '(
                id              INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
                pid             INT NOT NULL,
                section         INT NOT NULL DEFAULT 0,

                has_picture     INT NOT NULL DEFAULT 0,
                position        INT NOT NULL DEFAULT 0,
                catalog_views   INT NOT NULL DEFAULT 0,
                detail          INT NOT NULL DEFAULT 0,
                basket_count    INT NOT NULL DEFAULT 0,
                available       INT NOT NULL DEFAULT 0,
                price           INT NOT NULL DEFAULT 0,
                buy_count       INT NOT NULL DEFAULT 0,
                has_discount    INT NOT NULL DEFAULT 0,
                addition_time   INT NOT NULL DEFAULT 0,
                has_detail_text INT NOT NULL DEFAULT 0
            );';
        global $DB;
        return $DB->Query($sql_query, false);
    }

    public static function DestroyTable()
    {
        $sql_query = 'DROP TABLE IF EXISTS ' . self::getTableName();

        global $DB;
        return $DB->Query($sql_query, false);
    }

I'm trying to add an entry to the database like this
$t = array("pid" => 1);
    $res = MeasurmentTable::add($t);

The problem is that it is added but the pid value is 0, how to fix it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Ko1, 2015-01-03
@Ko1

The problem is related to writing field names in lowercase, should be in uppercase

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question