mardi 9 mars 2021

Laravel 5.5 - When changing SQL from the Raw Query, it doesn't work

I'm "fighting" with this problem for some days already and I believe I need help...

I tried many ways using different ways even trying to put in database.php the strict mode as false but it doesn't work too(we use supervisord to manage the laravel jobs, and when we do changes in any back end code, we need to reset the supervisord and start it again)...

Anyway, the full code is to generate excel files when putting an email in the text field.

I have the three queries below: the first one is the original one, and it is working fine in production but the other two don't work(second query: I tried to add another custid there together with order by but it didn't work. third query: then in the last query I just tried to add the simple "Order by" Desc and it didn't work also).

See the queries below(Oh yes, these queries work fine inside the MySQL Workbench but not inside laravel: they are inside a method):

  1. ORIGINAL:
$query = DB::connection('WeTd')
                    ->select("SELECT DISTINCT Inventory.*, Address.City, Address.State, Manufacturers.ManufacturerName
                        FROM Inventory
                        INNER JOIN Items ON Inventory.VINNumber = Items.VINNumber
                        INNER JOIN Address ON Items.DestinationAddr = Address.AddrID
                        INNER JOIN Manufacturers ON Inventory.CustID = Manufacturers.ManufacturerID
                        WHERE Address.AddressType = 'Destination'
                        AND Address.AddrID  'W165593'
                        AND Inventory.VINNumber = '{$vinNumber}';");

        return (!empty($query) && isset($query[0])) ? $query[0] : null;
  1. WITH CUSTOMER AND ORDER BY DESC
$query = DB::connection('WeTd')
                    ->select("SELECT DISTINCT Inventory.*, Address.City, Address.State, Manufacturers.ManufacturerName
                        FROM Inventory
                        INNER JOIN Items ON Inventory.VINNumber = Items.VINNumber
                        INNER JOIN Address ON Items.DestinationAddr = Address.AddrID
                        INNER JOIN Manufacturers ON Inventory.CustID = Manufacturers.ManufacturerID
                        WHERE Address.AddressType = 'Destination'
                        AND Address.AddrID  'W165593'
                        AND Inventory.VINNumber = '{$vinNumber}' AND Items.CustID = '571793' ORDER BY Items.Serial DESC;");

        return (!empty($query) && isset($query[0])) ? $query[0] : null;
  1. ONLY WITH ORDER BY DESC
$query = DB::connection('WeTd')
                    ->select("SELECT DISTINCT Inventory.*, Address.City, Address.State, Manufacturers.ManufacturerName
                        FROM Inventory
                        INNER JOIN Items ON Inventory.VINNumber = Items.VINNumber
                        INNER JOIN Address ON Items.DestinationAddr = Address.AddrID
                        INNER JOIN Manufacturers ON Inventory.CustID = Manufacturers.ManufacturerID
                        WHERE Address.AddressType = 'Destination'
                        AND Address.AddrID  'W165593'
                        AND Inventory.VINNumber = '{$vinNumber}' ORDER BY Items.Serial DESC;");

        return (!empty($query) && isset($query[0])) ? $query[0] : null;

You guys have any solution? Thank you.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2O9EGvj
via IFTTT

Aucun commentaire:

Enregistrer un commentaire