[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Getting datatype on pdo Bind

Posted on 2010-09-21
7
Medium Priority
?
390 Views
Last Modified: 2013-12-12
Hi,

I've go this method:

public function getTables($procname,$parameter) {
      //see : http://www.php.net/manual/en/pdo.prepared-statements.php example #10 and #11
      $vars = explode(",", $parameter);
      $num = count($vars);
      //create holders for calls
      for ($i = 0; $i <= $num; $i++) {
         $holder.="?";
         if ($i != $num)
         {
            $holder.=",";
         }
      }
      $stmt = DBO::prepare("EXECUTE " . $procname . " " . $holder);
      // TODO build bind, may need to change type for strings and ints and others
      // perhaps look to put into dbcalls
      for ($i = 0; $i <= $num; $i++) {
         $stmt->bindParam($i + 1, $vars[$i], PDO::PARAM_STR | PDO::PARAM_INPUT_OUTPUT, PDO::ERRMODE_WARNING, 4000);
      }

// call the stored procedure
      try
      {
        $stmt->execute();
      } catch (PDOException $e)
      {

         //var_dump($e);
      }
      $data = ($stmt->fetchAll(PDO::FETCH_ASSOC));
      $stmt->closeCursor();
      return $data;
   }

Open in new window


It dynamically extracts data from a database, It has one problem though, it treats the id columns it finds as floats as opposed to integers, ie 2345 comes back a 2345.0, ideally the call should detect that the column is a id and display it as so. Does anyone know how how this could be done?

It could be done by post processing the data, but I would like to prevent that.
0
Comment
Question by:darren-w-
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 3

Assisted Solution

by:Progressed
Progressed earned 800 total points
ID: 33723948
and your sure that the ID is correctly in the DB?
0
 
LVL 13

Author Comment

by:darren-w-
ID: 33724103
yes
0
 
LVL 17

Expert Comment

by:jrm213jrm213
ID: 33725912
what data type is the "id" field in the database?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 13

Author Comment

by:darren-w-
ID: 33726067
PK,numeric(18,0) this is in MS SQL
0
 
LVL 17

Accepted Solution

by:
jrm213jrm213 earned 1200 total points
ID: 33726305
that is equivalent to decimal(18,0), since not storing any scale, I don't see why this would be chosen as the datatype over int, but thats beyond the case.

It is coming back with .0 because of the datatype. You could cast or convert the return value before returning it so that it displays the way you want, or you could use intval php function to convert it to an integer before displaying it.
0
 
LVL 13

Author Comment

by:darren-w-
ID: 33760657
Unfortunately I have now way of knowing what the data type of each field is going to be before the procedure is called,  but this will not be a problem in most cases as the data will be imported into a spreadsheet.

The id fields show up on the database as integers, will need to ask the db owner why they us this instead if an integer.

Have got around the problem using casting.
0
 
LVL 13

Author Closing Comment

by:darren-w-
ID: 33760661
Used casting in receiving script
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
Suggested Courses

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question