<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

class TestMssql extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'app:test:mssql';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Test MS SQL connection';

    /**
     * Execute the console command.
     */
    public function handle(): void
    {
        $server = 'WIN-NQERDFNLO4E';//'SRV-GALAXY';
        $config = array(
            "Database" => 'MeteorTest',//'GalaktikaAMM',
            //"UID" => 'test',
            //"PWD" => 'test',
            //"CharacterSet" => "UTF-8"
        );

        sqlsrv_configure("WarningsReturnAsErrors", 0);
        $conn = sqlsrv_connect($server, $config);
	
	if($conn) {
        	//$query = 'SELECT * FROM dbo.Валюта';
		$query = 'SELECT * FROM dbo.Test1';

	        $stmt = sqlsrv_query($conn, $query);
        	if($stmt !== false) {
            		$arrayResult = array();
            		while( $row = sqlsrv_fetch_array($stmt, SQLSRV_FETCH_ASSOC) ) {
            	    		$arrayResult[] = $row;
            		}

	            	sqlsrv_free_stmt($stmt);
        	    	print_r($arrayResult);
        	}
		else {
			print_r(sqlsrv_errors());
		}
		sqlsrv_close($conn);
	}
	else {
		print_r('error');
			
	}
    }
}
