Spiria Posted March 22, 2020 Share Posted March 22, 2020 I was trying the $database variable just for the purpose of figure it out. I have a custom table placed in a PW database and try to populate it with some data. I use this code. I don't want to use fields and page creation for this feature: public function saveMessage(array $data): int { $database = wire('database'); $statement = "INSERT INTO pm (pageId, title, ownerId, correspondentId,message,thetime,ownerRead,correspondentRead)" . " VALUES (:pageId, :title, :ownerId, :correspondentId,:message,:thetime,:ownerRead,:correspondentRead)"; $query = $database->prepare($statement); $query->bindValue(':pageId', $data[0], \PDO::PARAM_INT); $query->bindValue(':title', $data[1], \PDO::PARAM_STR); $query->bindValue(':ownerId', $data[2], \PDO::PARAM_INT); $query->bindValue(':correspondentId', $data[3], \PDO::PARAM_INT); $query->bindValue(':message', $data[4], \PDO::PARAM_INT); $query->bindValue(':thetime', $data[5], \PDO::PARAM_INT); $query->bindValue(':ownerRead', $data[6], \PDO::PARAM_BOOL); $query->bindValue(':correspondentRead', $data[5], \PDO::PARAM_BOOL); try { $query->execute(); $result = $query->rowCount(); $query->closeCursor(); } catch (\Exception $e) { $result = 0; } return $result; } If I dump the $query statement after binding the values, I get this, which shows that the values are not bound. object(PDOStatement)#279 (1) { ["queryString"]=> string(201) "INSERT INTO pm (pageId, title, ownerId, correspondentId,message,thetime,ownerRead,correspondentRead) VALUES (:pageId, :title, :ownerId, :correspondentId,:message,:thetime,:ownerRead,:correspondentRead)" } I use the 3.0.153 dev branch and my function is placed in a page Class (wonderful feature!) Of course, nothing is saved in the database. What am I missing? Link to comment Share on other sites More sharing options...
Spiria Posted March 22, 2020 Author Share Posted March 22, 2020 My bad... everything is fine. A table name was not correctly written ...? 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now