PHPize Online / SQLize Online  /  SQLtest Online

A A A
Share      Blog   Popular
Copy Format Clear
CREATE TABLE table1 ( id INT UNSIGNED AUTO_INCREMENT, type INT NOT NULL, PRIMARY KEY (id) ); CREATE INDEX my_idx ON table1 (type); INSERT INTO table1 (type) VALUES (1), (1), (1), (2), (2), (3);
Copy Clear
Copy Format Clear
<?php $view = 'SELECT type from table1 UNION ALL SELECT type from table1'; $query = "EXPLAIN SELECT * FROM ($view) as v WHERE type = ?;"; $type = 2; $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); $stmt = $pdo->prepare($query); $stmt->bindParam(1, $type, PDO::PARAM_INT); $stmt->execute(); $result = $stmt->fetchAll(PDO::FETCH_ASSOC); print_r($result); function dumpTable( array|Collection $data, string $style = 'box' ): mixed { if (is_array($data)) { $data = collect($data); } $array = $data->map(fn ($row) => (array) $row)->all(); $output = new BufferedOutput(); $table = new Table($output); $table->setStyle($style); $table->setHeaders(array_keys($array[0] ?? [])); $table->setRows($array); $table->render(); $tableCode = htmlspecialchars(trim($output->fetch())); if ($style === 'markdown') { $tableRows = explode("\n", $tableCode); array_shift($tableRows); array_pop($tableRows); $tableCode = implode("\n", $tableRows); } echo "<pre style=\"margin-bottom: 40px\">$tableCode</pre>"; return $data; }
Show:  
Copy Clear