Added plugins and build tools
This commit is contained in:
		
							
								
								
									
										36
									
								
								plugins/com.noccy.pdo/PdoExecCommand.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										36
									
								
								plugins/com.noccy.pdo/PdoExecCommand.php
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,36 @@
 | 
			
		||||
<?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");
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
		Reference in New Issue
	
	Block a user