Solved

php msqli bind error

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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Join & Write a Comment

As a database administrator, you may need to audit your table(s) to determine whether the data types are optimal for your real-world data needs.  This Article is intended to be a resource for such a task. Preface The other day, I was involved …
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now