1

When I run the following code with mysqli on machine a there is no issue executing the query and reviewing the data. However on machine b, I receive the following error:

Warning: mysqli_stmt::bind_param(): invalid object or resource mysqli_stmt

I am unsure as to why this would be. Does this error occur on anyone else's machine?

<?php 
$dbHost = "localhost";
$dbUser = 'ben2';
$dbPass = 'ben';
$dbname = 'test';

$mysqli = new mysqli($dbHost, $dbUser, $dbPass, $dbname);
 if ($mysqli->connect_error) {
    die('Connect Error (' . $mysqli->connect_errno . ') '
        . $mysqli->connect_error);
}

$firstname = "David";
$lastname = "Peterson";

$stmt = $mysqli->stmt_init();
$stmt->prepare("INSERT INTO test (fn, ln) VALUES (?, ?)");
$stmt->bind_param("ss", $firstname, $lastname);
$stmt->execute();   
?>
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
Ben Pelletier
  • 33
  • 1
  • 4
  • 1
    Try adding `echo mysqli_error($mysqli);` and `var_dump($stmt);` see what other error messages you get and if there's anything in `$stmt` - It could be a bad connection or as the present error message states, an `invalid object` - Googling your error message produced many different possible scenarios. – Funk Forty Niner Mar 11 '14 at 17:34
  • 1
    thanks, i was able to uncover he real issue by echoin the error – Ben Pelletier Mar 11 '14 at 19:13
  • You're welcome, glad to hear it. – Funk Forty Niner Mar 11 '14 at 19:13
  • Does this answer your question? [mysqli\_fetch\_assoc() expects parameter / Call to a member function bind\_param() errors. How to get the actual mysql error and fix it?](https://stackoverflow.com/questions/22662488/mysqli-fetch-assoc-expects-parameter-call-to-a-member-function-bind-param) – Dharman May 09 '20 at 19:27

0 Answers0