#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2016
    Location
    Lakewood, WA
    Posts
    199
    Rep Power
    17

    Problem binding values in PDO


    Having some problems with my PDO db class...

    Here's some code:
    PHP Code:
            // This binds as param verses value.
        
    public function bindParamSingle($param$value$type=null) { 
            echo 
    "Param: " $param ", Val: " $value ", Type: " $type "<br><br>";
            try {
                if (
    $type == null) { $type $this->setPDOParamType($value); }
                
    self::$PDOstmt->bindParam($param$value$type);
            }
            catch (
    PDOException $e) {
                echo 
    "<pre>";
                
    print_r($e);
                echo 
    "</pre>";
                
    //$errorHandler->PDOException($e);
            
    }
        } 
    The input is:

    Param: :chart_date, Val: 07 Aug 2017, Type: PDO::PARAM_STR

    I'm getting this error:
    Warning: PDOStatement::bindParam() expects parameter 3 to be integer, string given in
    Of course PDO::PARAM_STR isn't an int, but it's a constant that should be read as an int, shouldn't it?

    This particular function deals with queries that have a single value to bind, but of course I have a function that binds arrays of values...

    [EDIT]

    Nevermind... I was passing a string, as in "PDO::PARAM_STR" not PDO::PARAM_STR. Silly me.
    Last edited by Arty Zifferelli; August 6th, 2017 at 07:11 PM.
  2. #2
  3. Lazy Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,331
    Rep Power
    9645
    PDO::PARAM_STR is a constant whose value is an integer.

    "PDO::PARAM_STR" is a string.

    Whatever is calling bindParamSingle needs to use the constant, not the string.

IMN logo majestic logo threadwatch logo seochat tools logo