Solved

php msqli bind error

Posted on 2014-09-30
4
31 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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

756 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