I'm making a second connection of my project in laravel with a view in an MsSql database, I configured my .env and config correctly, however this is an error of memory overflow:
$ php artisan tinker
Psy Shell v0.10.5 (PHP 7.3.24-3+ubuntu18.04.1+deb.sury.org+1 — cli) by Justin Hileman
>>> use App\Condinvest\BoletoPropCondominio as BPC
>>> BPC::first();
Illuminate\Database\QueryException with message 'SQLSTATE[HY001] Unable to allocate sufficient memory (meudominio.com.br:5000) (severity 8) (SQL: select top 1 * from [View_Boleto_Prop_Condominio])'
>>>
already changed in my php.ini:
memory_limit = 128M
but the error continues.
My models briefly look like this:
BaseView.php
<?php
namespace App\Condinvest;
use Illuminate\Database\Eloquent\Model;
class BaseView extends Model
{
protected $connection = 'condinvest';
}
BoletoPropCondominio.php
<?php
namespace App\Condinvest;
class BoletoPropCondominio extends BaseView
{
protected $table = 'View_Boleto_Prop_Condominio';
protected $fillable = [
'Id_Condo_lan',
...
'Id_titular'
];
}
when I do the same query directly through the command terminal:
SELECT TOP 1 * FROM View_Boleto_Prop_Condominio;
returns my data successfully.
Can anyone tell me what may be happening, or how I can debug better to understand where the error is, please.
EDIT
>>> DB::connection('condinvest')->getConfig()['driver']
=> "sqlsrv"
Since the error is apparently being reported by the database process (not the php process), I would not expect changes to memory limits in php.ini to have any effect.
I found this issue which mentions this specific error when using a deprecated driver with MSSQL Server.
To check which driver Laravel is using, type DB::connection()->getConfig()['driver']
into your Tinker console. If you see sqlsrv
then everything is ok here, but if you see dblib
then this might be the source of the error. This problem was supposedly fixed in Laravel 5.7 to prefer the supported drivers if more than one is available, but it's also possible that your database.php
config file uses the wrong one.
It is also possible that the memory limits of the database server or the system it resides on are actually being exceeded. Being able to run the query in a command prompt without getting the error suggests that this is not the case, but it may still be worth investigating. If the available memory is very low then it's possible that there is not enough to run both php and the database query at the same time. You can check the available system memory by running the free -h
command in the terminal, as long as the database process is running on the same machine as your terminal. However, if you are using a shared hosting provider then it is possible that the database is on a separate machine.