I have been staring at a problem for far to long now.
I have a PHP file that is preparing an insert query, binding the params, and executing the query (Simple).
QUERY
$stmt = $db->prepare("SELECT insert_user(?, ?, ?, ?, ?, ?)"); For some reason the $stmt object returned by execute returns -1 for the affected rows. If I alter the code to do just an insert query with the values I wanted to bind, hard coded instead, the query works just fine.
HARD CODED QUERY
$db->query("SELECT insert_user('Test', 'Account', '[email protected]', 'testAccount9', '1980-01-01', 1)"); Something is going wrong in the bind_param section. I have errors turned on and am checking for mysqli errors too, but both are returning no errors.
PHP FILE
... $postdata = file_get_contents("php://input"); if (isset($postdata) && !empty($postdata)) { $request = json_decode($postdata); } if ( validate_string($request->fname) && validate_string($request->lname) && validate_integer(intval($request->gender))) { $stmt = $db->prepare("SELECT insert_user(?, ?, ?, ?, ?, ?)"); if ($stmt) { $stmt->bind_param("ssssis", $first_name, $last_name, $email, $password, $gender, $dob); $first_name = $request->fname; $last_name = request->lname; $email = $request->email; $password = password_hash($request->password, PASSWORD_BCRYPT); $gender = intval($request->gender); $dob = $request->dob; $stmt->execute(); if ($stmt->affected_rows > 0) { echo toJson('success'); } else { echo toJson('fail'); } } else { echo toJson("Prepare failed: (" . $db->errno . ") " . $db->error); } } else { echo toJson('fail - passed data not valid'); } ... I feel the error must be simple at this point, but I have tried at least 23,432 different things to no success.
SELECT!=INSERT. See dev.mysql.com/doc/refman/8.0/en/insert.htmlINSERT INTO table (column) VALUES (:column)