I've checked phpinfo(), and mysqli is enabled on my account.
Allright, the code I'm using is the same as is mentioned in the online php manual on the php website, on a test page on my website.
But it still gives me a variation of those above mentioned error messages, based on whether I'm using the procedural style or the object-oriented style for coding the parameterized query.
PHP Code:
<?php
$mysqli = new mysqli('localhost', 'username', 'password', 'databasename');
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$stmt = $mysqli->prepare("Insert Into Table (Date, Name, Email, VisitorIp, Text, Field6) Values (?, ?, ?, ?, ?, ?)");
$stmt->bind_param('sssssi', $Date, $Name, $Email, $VisitorIP, $Text, $Field6);
$Date = "1998-7-3";
$Name = "John Cusack";
$Email = "123@email.com";
$VisitorIP = "192.168.1.1";
$Text = "Test Data. Test Data.";
$Field6 = 1;
/* execute prepared statement */
$stmt->execute();
printf("%d Row inserted.\n", $stmt->affected_rows);
/* close statement and connection */
$stmt->close();
/* close connection */
$mysqli->close();
?>
(Some variables have been changed for security purposes, but I can attest that in the actual code they are accurately supplied)
This code throws the following error message -
Fatal error: Call to a member function bind_param() on a non-object in /home/[domain]/public_html/[webpage] on line n
Okay, here is the same code as above, but this time using procedural style, as opposed to the object-oriented style above.
PHP Code:
<?php
$link = mysqli_connect('localhost', 'username', 'password', 'databasename');
/* check connection */
if (!$link) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$stmt = mysqli_prepare($link, "Insert Into Table (Date, Name, Email, VisitorIP, Text, Field6) Values (?, ?, ?, ?, ?, ?)");
mysqli_stmt_bind_param($stmt, 'sssssi', $Date, $Name, $Email, $VisitorIP, $Text, $Field6);
$Date = "1998-7-3";
$Name = "John Cusack";
$Email = "123@email.com";
$VisitorIP = "192.168.1.1";
$Text = "Test Data. Test Data.";
$Field6 = 1;
/* execute prepared statement */
mysqli_stmt_execute($stmt);
printf("%d Row inserted.\n", mysqli_stmt_affected_rows($stmt));
/* close statement and connection */
mysqli_stmt_close($stmt);
/* close connection */
mysqli_close($link);
?>
Again, some details have been obscured for security purposes.
And these are the error messages I get this time 'round -
Warning: mysqli_stmt_bind_param() expects parameter 1 to be mysqli_stmt, boolean given in /home/[domain]/public_html/[webpage] on line n
Warning: mysqli_stmt_execute() expects parameter 1 to be mysqli_stmt, boolean given in /home/[domain]/public_html/[webpage] on line n
Warning: mysqli_stmt_affected_rows() expects parameter 1 to be mysqli_stmt, boolean given in /home/[domain]/public_html/[webpage] on line n
0 Row inserted.
Warning: mysqli_stmt_close() expects parameter 1 to be mysqli_stmt, boolean given in /home/[domain]/public_html/[webpage] on line n
And this is the page on the php website where I got the proforma code -
http://us2.php.net/manual/en/mysqli-stmt.bind-param.php