I'm running this PHP script but I'm get the following error:
PHP Fatal error: Call to a member function bind_param() on a non object in c:/test.php on line 16
Line 16 is:
$load_stmt->bind_param('ss', $filetobeloaded, $filetobeloaded);
Can someone tell me what is wrong with this statement?
Full script:
<?php
$mysqli = new mysqli('localhost', 'root', 'password', 'orangevalleedb');
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$file_query = "select filename from cdr";
$load_query = "LOAD DATA INFILE ? INTO TABLE cdr FIELDS TERMINATED BY ',' ENCLOSED BY '\"' LINES TERMINATED BY '\\n' ( @col_1, @col_2 )";
$file_stmt = $mysqli->prepare($file_query);
$file_stmt->execute();
$file_stmt->bind_result($filetobeloaded);
$load_stmt = $mysqli->prepare($load_query);
$load_stmt->bind_param('ss', $filetobeloaded, $filetobeloaded);
/* execute prepared statement */
while($file_stmt->fetch()) {
$load_stmt->execute();
}
/* close statement and connection */
$load_stmt->close();
$file_stmt->close();
/* close connection */
$mysqli->close();
?>
var_dump($load_stmt)to see what you get?$load_stmtis not an object. There's probably an error in your SQL query.