2021-12-08 23:58:28 +00:00
|
|
|
<?php
|
|
|
|
|
2021-12-23 14:31:26 +00:00
|
|
|
namespace SparkPlug\Com\Noccy\Pdo\Commands;
|
2021-12-08 23:58:28 +00:00
|
|
|
|
|
|
|
use Spark\Commands\Command;
|
|
|
|
use Symfony\Component\Console\Helper\Table;
|
|
|
|
use Symfony\Component\Console\Input\InputArgument;
|
|
|
|
use Symfony\Component\Console\Input\InputInterface;
|
|
|
|
use Symfony\Component\Console\Input\InputOption;
|
|
|
|
use Symfony\Component\Console\Output\OutputInterface;
|
|
|
|
|
|
|
|
class PdoExecCommand extends Command {
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output)
|
|
|
|
{
|
|
|
|
$source = $input->getOption("res");
|
|
|
|
$sourcePdo = get_resource($source)->getPDO();
|
|
|
|
if (!$sourcePdo) {
|
|
|
|
$output->writeln("<error>Invalid resource: {$source}</>");
|
|
|
|
return Command::INVALID;
|
|
|
|
}
|
|
|
|
|
|
|
|
$query = $input->getArgument('query');
|
|
|
|
|
|
|
|
$stmt = $sourcePdo->prepare($query);
|
|
|
|
$stmt->execute();
|
|
|
|
|
|
|
|
return Command::SUCCESS;
|
|
|
|
}
|
|
|
|
protected function configure() {
|
|
|
|
$this->setName("pdo:exec");
|
|
|
|
$this->setDescription("Run a query without returning data");
|
|
|
|
$this->addOption("res", "r", InputOption::VALUE_REQUIRED, "Resource to query", "db");
|
|
|
|
$this->addArgument("query", InputArgument::REQUIRED, "SQL query to execute");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|