Heroku cliにてログを確認したところ次のようなエラーが発生していました。
[04-Oct-2017 13:28:45 UTC] PHP Fatal error: Call to a member function prepare() on null in /app/index.php on line 118
コードは、次の通りです。
lang
1//ユーザーをデータベースに登録する 2function registerUser($userId, $stones) { 3 $dbh = dbConnection::getConnection(); 4 $sql = 'insert into '. TABLE_NAME_STONES .' (userid, stone) values(pgp_sym_encrypt(?, \'' . getenv('DB_ENCRYPT_PASS') . '\'), ?) ' ; 5 $sth = $dbh->prepare($sql); 6 $sth->execute(array($userId, $stones)); 7} 8 9//ユーザー情報を更新 10function updateUser($userId, $stones) { 11 $dbh = dbConnection::getConnection(); 12 $sql = 'update ' . TABLE_NAME_STONES . ' set stone = ? where ? = pgp_sym_decrypt(userid, \'' . getenv('DB_ENCRYPT_PASS') . '\')'; 13 $sth = $dbh->prepare($sql); 14 $sth->execute(array($stones, $userId)); 15} 16 17// ユーザーIDを元にデータベースから情報を取得 18function getStonesByUserId($userId) { 19 $dbh = dbConnection::getConnection(); 20 $sql = 'select stone from ' . TABLE_NAME_STONES . ' where ? = pgp_sym_decrypt(userid, \'' . getenv('DB_ENCRYPT_PASS') . '\')'; 21 $sth = $dbh->prepare($sql); 22 $sth->execute(array($userId)); 23 // レコードが存在しなければNULL 24 if (!($row = $sth->fetch())) { 25 return PDO::PARAM_NULL; 26 } else { 27 // 石の配置を連想配列に変換し返す 28 return json_decode($row['stone']); 29 } 30} 31
下から10行目のprepareに対してエラーが発生しているようです。
色々試しましたが解決できませんでした。
どなたか分かる方教えていただけると嬉しいです。
よろしくお願いいたします。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。