Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

php msqli bind error

Posted on 2014-09-30
4
Medium Priority
?
45 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
2 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 49

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

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

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

This article discusses how to implement server side field validation and display customized error messages to the client.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses

824 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