Solved

php msqli bind error

Posted on 2014-09-30
4
35 Views
Last Modified: 2016-05-23
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
0
Comment
Question by:jmckearney
[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 Comments
 

Accepted Solution

by:
jmckearney earned 0 total points
ID: 40356270
Problem solved.  This error can most confusing. The normal problems are bind params do not match bind types or the number of bound arguments.  Also the array containing the bind params must be a reference which it is.  In my case on the table column definition I was using was a timestamp.  I was unaware that a Timestamp generally can not be null.  So this error is sort of like I give up!
0
 
LVL 48

Expert Comment

by:PortletPaul
ID: 40356331
Thanks for reporting back, please initiate closure of the question choosing your comment above as the answer.

Cheers, Paul
0

Featured Post

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!

Question has a verified solution.

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

Suggested Solutions

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
These days socially coordinated efforts have turned into a critical requirement for enterprises.
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 dynamically set the form action using jQuery.

734 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