Propel ORM 1.6과 PostgreSQL을 사용하는 Symfony2 프로젝트가 있습니다. 나는 다음과 같은 방법으로 쿼리 using Custom SQL as shown in this link에서 행의 수를 얻으려고 :Propel 1.6의 사용자 지정 SQL을 사용하여 쿼리에서 행 수를 얻는 방법?
$con = Propel::getConnection(VerbNounPeer::DATABASE_NAME);
$countSql = "SELECT COUNT(*) FROM ("
." SELECT DISTINCT ON (fk_noun_id) *"
." FROM verb_noun"
." ORDER BY fk_noun_id, verb_noun_vote_count DESC"
.") inner_tb";
$countSqlStmt = $con->prepare($countSql);
$countSqlStmt->execute();
위의 쿼리가 잘 작동합니다. 그러나 stmt (위의 $ countSqlStmt) 객체에서 행 수의 정수 값을 얻는 방법은 무엇입니까?
나는 또한 시도 : $ countSqlStmt는 "... 배열로 형 DebugPDOStatement의 개체를 사용할 수 없습니다 치명적인 오류"개체가 아니라 내가 할 배열 인 점을 감안 그러나
$recordsCount = $countSqlStmt[0];
을 : 나는 사용하여 시도 추진의 포맷을 사용하여 배열로 변환합니다 :
$countSqlFormatter = new PropelArrayFormatter();
$countSqlRow = $countSqlFormatter->format($countSqlStmt);
그러나이 작동하지 않는 중 내가 배열에 대한 기준을 지정해야합니다, 나의 질의 결과는 단지이기 때문에 내가 넣어 해야할지하지 않는 count가 아닌 클래스가 아닌 행. 그것은 클래스를 사용하는 경우 :
$formatter->setClass('VendorName\NameBundle\Model\VerbNoun');
어떤 아이디어? this link there is a use of PropelArrayFormatter()에서 그것은 내게 큰 도움이되지 못했습니다 ...
K-Phoen에 감사드립니다. 그것은 실제로 실종 된 것입니다! 나는 결국 매우 기본적인 것 같아요 ... 다음 작동합니다 : $ countSqlStmt = $ con-> prepare ($ countSql); $ countSqlStmt-> execute(); $ countArray = $ countSqlStmt-> fetch(); $ recordsCount = $ countSqlStmt [0]; – RayOnAir