37 lines
1.2 KiB
PHP
37 lines
1.2 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace SparkPlug\Com\Noccy\Pdo;
|
||
|
|
||
|
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");
|
||
|
}
|
||
|
}
|
||
|
|