Welcome Guest, Not a member yet? Register   Sign In
Leading zeroes to decimal value less than one
#1

We are using codeigniter 4 with microsoft sql server 2016 and we fetch data having decimal values less than zero, zero before dot getting removed.

After analysis of issue able to find that issue with sql server and they added below option from version pdo_sqlsrv v5.6.0, Below code which works for core php :

Code:
$attrs = array(PDO::SQLSRV_ATTR_FORMAT_DECIMALS => true);
$pdo = new PDO("sqlsrv:Server=" . $hostname . ";Database=" . $database, $username, $password,$attrs);

But didn't found way to do same with ci4 i.e. applying PDO::SQLSRV_ATTR_FORMAT_DECIMALS => true.

Thanks in advance.
Reply
#2

Now CI4 has no PDO drivers.

> MSSQL via the SQLSRV driver (version 2005 and above only)
Reply
#3

(01-07-2022, 06:58 PM)kenjis Wrote: Now CI4 has no PDO drivers.

> MSSQL via the SQLSRV driver (version 2005 and above only)
Thank you Kenjis for quick reply.

I have found same param in sqlsrv as in pdo to add leading zero before dot and param for sqlsrv is FormatDecimals.

Below is the code working by directly putting option in sqlsrv connection class connect method of vendor :
PHP Code:
$connection = [
            'UID'                  => empty($this->username) ? '' $this->username,
            'PWD'                  => empty($this->password) ? '' $this->password,
            'Database'            => $this->database,
            'ConnectionPooling'    => $persistent 0,
            'CharacterSet'        => $charset,
            'Encrypt'              => $this->encrypt === true 0,
            'ReturnDatesAsStrings' => 1,
            'FormatDecimals'  => 1
        
]; 


As its not a way to have custom code in vendor so can you help if there is any other way to set FormatDecimals = 1 ?
Reply
#4

(01-10-2022, 02:10 AM)Sureshkumar Wrote: As its not a way to have custom code in vendor so can you help if there is any other way to set FormatDecimals = 1 ?

The parameter FormatDecimals is not supported in the current SQLSRV driver.
I recommend you send a bug report or a pull request to support it.
https://github.com/codeigniter4/CodeIgni.../README.md

All you can do now is to create extended driver:
https://forum.codeigniter.com/thread-782...#pid383813
Reply
#5

(01-10-2022, 07:23 PM)kenjis Wrote:
(01-10-2022, 02:10 AM)Sureshkumar Wrote: As its not a way to have custom code in vendor so can you help if there is any other way to set FormatDecimals = 1 ?

The parameter FormatDecimals is not supported in the current SQLSRV driver.
I recommend you send a bug report or a pull request to support it.
https://github.com/codeigniter4/CodeIgni.../README.md

All you can do now is to create extended driver:
https://forum.codeigniter.com/thread-782...#pid383813
Thank you so much Kenjis Smile 

For now i have resolved issue by extending sqlsrv driver and I will report a bug regarding same.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB