0

When I am trying to insert row with below snippet, it throwing the strict standard warning for $user_info_do->get_first_name() where user_info_do is class with member variable first_name.

ERROR: Strict standards: Only variables should be passed by reference

$query = "INSERT INTO user_info ( first_name ) VALUES (?);";

if( !($query_stmt = $this->m_db_connection->prepare($query))) {         
   return;
}

if( !$query_stmt->bind_param("s", $user_info_do->get_first_name() ) {
   return;
}

Please help me what could be the reason here.

raina77ow
  • 103,633
  • 15
  • 192
  • 229
  • possible duplicate of [mysqli : Strict Standards: Only variables should be passed by reference](http://stackoverflow.com/questions/23843383/mysqli-strict-standards-only-variables-should-be-passed-by-reference) – raina77ow Dec 13 '14 at 13:08

2 Answers2

1

The problem is that bind_param binds variables to a prepared statements (their values will be extracted when statements are sent to DB), and you attempt to pass a value (result of $user_info_do->get_first_name()) into it. That's why you get an error: values cannot be passed by reference.

Change your code into something like...

$firstName = $user_info_do->get_first_name();
if( !$query_stmt->bind_param("s", $firstName ) ) {
  return;
}
raina77ow
  • 103,633
  • 15
  • 192
  • 229
0

$query_stmt->bind_param requires all params to be passed by reference, so you can't pass function's return value directly (without assigning it to a variable first, that is).

mysqli : Strict Standards: Only variables should be passed by reference

Community
  • 1
  • 1
fortune
  • 3,361
  • 1
  • 20
  • 30