Link to home
Start Free TrialLog in
Avatar of jmckearney
jmckearney

asked on

php msqli bind error

I have written a PHP class library to provide access to MySQL via MySqlI.  For creates and updates to records
I use a prepared statement.  Since a record can a variable number of columns and types based on who is using it for what table I generate the bind mask.  Well it works fine for one table and I get the bind error, param 1 expects a callback.

call_user_func_array(array($this->stmt, 'bind_param'), $val) <--- the working / failing call.

// To give a sense of the whole

        public function bindStmt($b, $vals)
        {
            $val = array();
            //$this->stmt = $this->mysql->stmt_init();
            $val[] = $b;
            for ($x = 0; $x < count($vals); $x++)
                $val[] = &$vals[$x];

            call_user_func_array(array($this->stmt, 'bind_param'), $val);
            //$this->stmt->bind_param($b, $vals[0], $vals[1], $vals[2],$vals[3]);
            $this->stmt->execute();
            $this->stmt->close();
            $this->stmt = null;
        }
// A record get defined here via a predefined array of columns.
       self::$_updateCols = (new ColumnArray())
            ->addColumn(new Column("shortName", "Short Name", Column::STRING, self::$_table))
            ->addColumn(new Column("longName", "Long Name", Column::STRING, self::$_table))
            ->addColumn(new Column("updated_at", "Last Update", Column::DATETIME, self::$_table));
 
       public function update($id, $shortName, $longName)
        {
            $ret = "";
            try
            {
                $record = new Record("Contact Type Record");
                $record->setTable(ContactTypeDefs::table());
                $record->addColumn(ContactTypeDefs::updateCols());
                $record->setColumnValue('shortName', $shortName)
                    ->setColumnValue('longName', $longName)
                    ->setColumnValue('updated_at', null);
                $record->setRecordForUpdate();
                $record->addKeyDef('KEY');
                $record->setKeyDefValue('KEY', $id);
                $ds = new DataSet("Update Contact Type");
                $ds->addRecord($record);
                $ds->setConnection($this->sql);
                $ds->exec();
                $ret = "Record Updated [$id: $longName]";
            } catch (Exception $e)
            {
                $ret = $e;
            } finally
            {
               return $ret;
            }
        }
 Like I said sometimes it works and sometimes it fails with:

call_user_func_array() expects parameter 1 to be a valid callback, first array member is not a valid class name or object
ASKER CERTIFIED SOLUTION
Avatar of jmckearney
jmckearney

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of PortletPaul
Thanks for reporting back, please initiate closure of the question choosing your comment above as the answer.

Cheers, Paul