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->st mt, '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->st mt, '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(ContactT ypeDefs::t able());
$record->addColumn(Contact TypeDefs:: updateCols ());
$record->setColumnValue('s hortName', $shortName)
->setColumnValue('longName ', $longName)
->setColumnValue('updated_ at', null);
$record->setRecordForUpdat e();
$record->addKeyDef('KEY');
$record->setKeyDefValue('K EY', $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
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
// 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(
$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(ContactT
$record->addColumn(Contact
$record->setColumnValue('s
->setColumnValue('longName
->setColumnValue('updated_
$record->setRecordForUpdat
$record->addKeyDef('KEY');
$record->setKeyDefValue('K
$ds = new DataSet("Update Contact Type");
$ds->addRecord($record);
$ds->setConnection($this->
$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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Cheers, Paul