0

I have a bit of a trouble about CodeIgniter and MS SQL.

Here is my story:

I am using CodeIgniter 3 and MS SQL Server as database. I created a stored procedure in MS SQL:

-- add_material 'FG-0505-9999', 'Dan - yeah, x','B-Go! Layered Cake','Special Cakes',  'TEST', 'TEST',  'TEST', 'TEST', 'TEST', 10, 10,10,10, 10, 'TEST'

ALTER procedure [dbo].[add_material]
 @material_code nvarchar(max), 
 @material_group nvarchar(max),
 @material_group_description nvarchar(max),
 @base_unit nvarchar(max),
 @external_material_group nvarchar(max),
 @material_description nvarchar(max),
 @product_category nvarchar(max),
 @product_name nvarchar(max),
 @product_name2 nvarchar(max),
 @case_divisor decimal(18, 4),
 @pack_divisor decimal(18, 4),
 @piece_divisor decimal(18, 4),
 @material_price decimal(18, 4),
 @is_active int,
 @material_group1_name nvarchar(max)
as

begin
  insert into BigEMasterData.dbo.tbl_Materials
  (MatrlCode, 
  MatGrp, 
  MatGrpDesc,
  BsUnit,
  ExtMatGrp,
  MatDesc,
  ProdCat,
  ProdNm,
  ProdNm2,
  CaseDiv,
  PackDiv,
  PieceDiv,
  MatPrce,
  IsActive,
  MG1Nm)
  values(@material_code, 
      @material_group,
      @material_group_description,
      @base_unit,
      @external_material_group,
      @material_description,
      @product_category,
      @product_name,
      @product_name2,
      @case_divisor,
      @pack_divisor,
      @piece_divisor,
      @material_price,
      @is_active,
      @material_group1_name)
 end

and here is the Model that calls that procedure:

  public function add_material($material_code, $material_group, $material_group_description, $base_unit, $external_material_group, $material_description, $product_category, $product_name, $product_name2, $case_divisor, $pack_divisor, $piece_divisor, $material_price, $is_active, $material_group1_name)
  {
    $result = $this->dbmasterdata->query("add_material $material_code, $material_group, $material_group_description, $base_unit, $external_material_group, $material_description, $product_category, $product_name, $product_name2, $case_divisor, $pack_divisor, $piece_divisor, $material_price, $is_active, $material_group1_name");
    if (!$result) {
      return $this->dbmasterdata->error();
    }
  }

Here is the sample data entry/form:

enter image description here

Now, if I click save it keeps showing me an error:

enter image description here

Now, I am wondering where the error is coming from. I have investigated to my best and here's what I found out:

  • If I execute the store procedure in MS SQL Management Studio, and provided the same data in the given form(on the screenshot), it works fine. It inserts the data.
  • But as I said if the data came from the form it gives me the error.

Now, is it safe to assume that PHP or CodeIgniter, is doing something to my data before passing it to MS SQL? is it the special characters?

Hope you would enlighten about this, or guide me where to look. I have been searching this, I hope someone with same experience would help.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Dan Angelo Alcanar
  • 369
  • 2
  • 3
  • 13
  • 1
    For this type of debugging, the SQL Server Profiler is your friend as you can log exactly what is being called and passed, and see for yourself what the problem is. – TomC Aug 07 '18 at 04:43
  • @Hackerman, thanks for pointing me to the answer. It works.... – Dan Angelo Alcanar Aug 07 '18 at 05:32

0 Answers0