I have a connection class to the sqlClass database and in it I registered the query_exec method that executes the SQL queries.
I also have another pageNavClass class and it has a SQL parameter to count the number of cells in a particular table. (in general, it is planned to use any table), and there is also a usersClass user usersClass inherited from sqlClass , in the usersClass user usersClass there is a listAllUsers method that should return the result of all counted cells to the specified one. range. through the declared pageNavClass in it.
A question how to connect two classes usersClass and pageNavClass , without using inheritance. I need to get the query_exec method from sqlClass so that I can use SQL queries in naveNavClass declared for example in usersClass ?
UPD!
// MySQL Connection connection.php class Connection { private $connect_result; function Connection(){ require_once ('includes/config.inc.php'); $dsn = "mysql:host=".DBHOST.";dbname=".DBNAME.";charset=".CHARSET; $opt = array( PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC ); try { $this->connect_result = new PDO($dsn, DBUSER, DBPASS, $opt); } catch (Exception $e) { die("Error! " . $e); } /* Исполняем все необходимое, что нужно обсолютно везде */ $this->loadLanguage(); $this->users_online(); $this->AuthStatus(); //var_dump(AUTH_STATUS); } public function getCon() { return $this->connect_result; } // метод выполнения запроса SQL !!! public function queryExec($sql, $data=false){ $stmt = $this->getCon()->prepare($sql); if (!$data) $stmt->execute(); else $stmt->execute($data); return $stmt; } } class PageNav { function navigation ($sql) { // Переменная хранит число сообщений выводимых на станице $num = 25; // Извлекаем из URL текущую страницу $page = 1; if (!empty($_GET['page'])) { $page = intval($_GET['page']); if ($page < 1) { $page = 1; } } // Определяем общее число сообщений в базе данных $result->queryExec("SELECT COUNT(*) FROM post")->fetch(); // Находим общее число страниц $total = intval(($posts - 1) / $num) + 1; // Определяем начало сообщений для текущей страницы $page = intval($page); // Если значение $page меньше единицы или отрицательно переходим на первую страницу // А если слишком большое, то переходим на последнюю if(empty($page) or $page < 0) $page = 1; if($page > $total) $page = $total; // Вычисляем начиная к какого номера следует выводить сообщения $start = $page * $num - $num; // Выбираем $num сообщений начиная с номера $start $result->queryExec("SELECT * FROM post LIMIT $start, $num"); // В цикле переносим результаты запроса в массив $postrow while ( $postrow[] = mysql_fetch_array($result)) echo "<table>"; for($i = 0; $i < $num; $i++) { echo "<tr> <td>".$postrow[$i]['name']."</td> <td>".$postrow[$i]['time']."</td></tr> <tr><td colspan=\"2\">".$postrow[$i]['text']."</td></tr>"; } echo "</table>"; } } // users.class.php class Users extends Connection{ public function listAllEventUsers() { $this->navPage = new PageNav(); $sql['count'] = "SELECT COUNT(*) FROM users_for_events"; // $start, $num $sql['fetch'] = "SELECT * FROM users_for_events LIMIT ?, ?"; $this->navPage->navigation($sql); return ; // array with all users } } 
sqlClassclass that works with the database and its connections .... This is a fanaticism and perverted. Especially not related to him in any way the class of users ....sqlClassyou should be final .. - Alexey Shimansky