<?php
echo "Lets run the program";
$id = 1;
$conn = new mysqli('localhost', 'root', 'root');
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$stmt = $conn->stmt_init();
if($stmt->prepare("Select Genre_Name from Practice.genre_list where Genre_ID = ?")){
$stmt->bind_param(i,$id );
$stmt->execute();
$stmt->bind_result(s, $result);
$stmt->fetch();
echo $result;
echo "in if function";
}
else{
echo "some issue";
}
?>
output:
Lets run the program Warning: mysqli::mysqli(): (HY000/2002): No such file or directory in /Applications/MAMP/htdocs/practice/preparedStatement.php on line 5 Connect failed: No such file or directory
After searching on web, I checked the configuration in php.ini file and mysql.sock is set properly, no issues with that. Still not able to figure out why prepared statement is not working, I am able to connect using traditional approach of mysqli_connect(), but not with the OOA approach.