B
B
biryukovm2021-07-26 07:40:57
PHP
biryukovm, 2021-07-26 07:40:57

PDO array output without numbering so that there are only variables?

How to output only variables?

class Database{
    private $host      = "****";
    private $port      = "3311";
    private $user      = "u_pars";
    private $pass      = "*****";
    private $dbname    = "p_pars";
    private $charset    = "utf8";
 
    private $dbh;
    public $error;
    private $stmt;
    private $sqlNum, $allTime = 0;

    public function __construct(){
        
        $dsn = 'mysql:host=' . $this->host . ';port=' . $this->port . ';dbname=' . $this->dbname . ';charset=' . $this->charset;// Установить DSN
        // Настройка параметров
        $options = array(
            //PDO::ATTR_PERSISTENT         => true,
            //PDO::ATTR_ERRMODE            => PDO::ERRMODE_EXCEPTION
            //PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"
            PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
            PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
        );
        // Создает новый объект PDO
        $this->dbh = null;
        try{
            $start = $this->getmicrotime();
            $this->dbh = new PDO($dsn, $this->user, $this->pass, $options);
            $stop = $this->getmicrotime();
            $this->allTime += $stop-$start;
        }catch(PDOException $e){$this->error = $e->getMessage()."\r\n";}// Ловим ошибки
    }

    public function query($query){
        IF ($query){
        $this->sqlNum++;
        $start = $this->getmicrotime();
        $this->stmt = $this->dbh->prepare($query);
        $stop = $this->getmicrotime();
        $this->allTime += $stop-$start;
        }
    }


The conclusion that is now
Array
(
    [0] => Array
        (
            [id] => 1
            [0] => 1
            [url_key] => 
            [1] => 
            [url] => url
            [2] => url
            [fl_obrabotka] => 1
            [3] => 1
            [fl_no_obrabotka] => 0
            [4] => 0
            [fl_404] => 0
            [5] => 0
            [fl_err] => 0
            [6] => 0
            [p1] => Источник группы
            [7] => Источник группы
            [p2] => 1.	Группа
            [8] => 1.	Группа
            [p3] => 2.	Подгруппа
            [9] => 2.	Подгруппа
            [p4] => 3.	Артикул 
            [10] => 3.	Артикул 
            [p5] => 4.	Назва 
            [11] => 4.	Назва 
            [p6] => 5.	Виробник
            [12] => 5.	Виробник
            [p7] => 6.	Оригинальный номер 
            [13] => 6.	Оригинальный номер 
            [p8] => 7.	Цена 
            [14] => 7.	Цена 
            [p9] => 8.	Наличие (6)  или есть или нет
            [15] => 8.	Наличие (6)  или есть или нет
            [p10] => 9.	Картинка. 
            [16] => 9.	Картинка. 
            [p11] => 10.	Аналоги в виде артикул + виробник
            [17] => 10.	Аналоги в виде артикул + виробник
            [p12] => 11.	Оригиналы. На вкладке оригиналы собрать все номера под этот артикул 
            [18] => 11.	Оригиналы. На вкладке оригиналы собрать все номера под этот артикул 
        )


As you can see, the information is duplicated and it's not very convenient to work
[p12] => 11. Originals. On the originals tab, collect all numbers under this article
[18] => 11. Originals. On the originals tab, collect all numbers under this article

. Therefore, it is necessary that the output be only for variables like p1, p2, etc.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question