Giter Site home page Giter Site logo

Comments (3)

yitam avatar yitam commented on May 22, 2024

Hi @david-garcia-garcia , to fetch numeric values as numbers rather than strings simply do this $conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true);

Please confirm.

from msphpsql.

meet-bhagdev avatar meet-bhagdev commented on May 22, 2024

@david-garcia-garcia : Does @yitam's recommendation help?

from msphpsql.

yitam avatar yitam commented on May 22, 2024

Hi @david-garcia-garcia

First and foremost, I believe the varbinary issue is already fixed by Pull Request #297. Please verify.

Moreover, for numeric types and buffered queries, I don't think the problem exists anymore. Here is my simple script:

$conn->exec("CREATE TABLE testTable (col1 int, col2 float, col3 real)"); 
$conn->setAttribute( PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE, true);

$stmt = $conn->prepare('INSERT INTO testTable VALUES (5, 0.57, 123.456)'); 
$stmt->execute(); 
        
$stmt = $conn->prepare("select * from testTable", array(PDO::ATTR_CURSOR => PDO::CURSOR_SCROLL, PDO::SQLSRV_ATTR_CURSOR_SCROLL_TYPE => PDO::SQLSRV_CURSOR_BUFFERED));

if ($stmt->execute()){
     $row = $stmt->fetchObject();
     var_dump($row);
}

The output I got is

object(stdClass)#2 (3) {
  ["col1"]=>
  int(5)
  ["col2"]=>
  float(0.57)
  ["col3"]=>
  float(123.45600128174)
}

Without PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE set to true, I got output like this

object(stdClass)#2 (3) {
  ["col1"]=>
  string(1) "5"
  ["col2"]=>
  string(4) "0.57"
  ["col3"]=>
  string(7) "123.456"
}

Therefore, we will close this issue. Please feel free to reopen it if you still experience similar problems.

from msphpsql.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.