Suppose I have a text DB in it a text table in its id and text I need to output text to a tag

<p>text</p> 

    1 answer 1

    First, connect to the database:

     <?php try { $pdo = new PDO('mysql:host=Название хоста (у вас наверняка localhost);dbname=название БД','имя пользователя','пароль'); } catch (Exception $e) { echo $e->getMessage(); } ?> 

    Then make a request to fetch data from the table:

     $stmt = $pdo->query('select * from text'); 

    Further in the loop (if you have several rows of records) output as follows:

     if($stmt->rowCount() > 0){ while($res = $stmt->fetch(PDO::FETCH_BOTH)){ echo '<p>'.$res['text'].'<p>'; } } 

    If you want to display 1 entry:

     $res= $stmt->fetch(); echo '<p>'.$res['text'];.'</p>'; 

    You can do this directly in html, then just do not forget to insert php tags. For example:

     <p><?php echo $res['text']; ?></p>