Skip to content

Commit

Permalink
Added support query for sqlite
Browse files Browse the repository at this point in the history
  • Loading branch information
yourjhay committed May 18, 2020
1 parent f816e27 commit c4b018e
Showing 1 changed file with 31 additions and 3 deletions.
34 changes: 31 additions & 3 deletions src/Simple/Engine/Console.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ private function migrate($file, $com)
try {
$table = 'users';
$db = new PDO("sqlite:"."./database/database.db");
$db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
if($file=='-c'){
$sql = $com;
Expand All @@ -323,10 +324,37 @@ private function migrate($file, $com)
password_hash TEXT NOT NULL,
reset_token TEXT NULL)";
}
echo($sql);

echo PHP_EOL;
$db->exec($sql);
print("Command successfull\n");
$command_ = explode(' ',$sql);
if(strtoupper($command_[0]) === "SELECT"){
$res = $db->query($sql);
$i=0;
$col=[];
$rows=[];
$v=[];
$table = new \LucidFrame\Console\ConsoleTable();
foreach($res as $row)
{
$i++;
foreach($row as $key => $val){
if($i==1){
$col[] .= $key;

} $v[]=$val;
}
$rows[$i] = $v;
unset($v);
}
$table->setHeaders($col);
foreach($rows as $r){
$table->addRow($r);
}
$table->display();
}else{
$c = $db->exec($sql);
print("Command successfull. $c affected rows.\n");
}
} catch (Exception $e) {
echo "Unable to connect".PHP_EOL;
echo $e->getMessage();
Expand Down

0 comments on commit c4b018e

Please sign in to comment.