0

Is it possible to place PHP logic that connects to a database into HTMl?

For example, I have the following index.php which has HTML in it however I will like to do the reverse where I have index.html and have PHP in it.

For example, is it possible to place the following logic in my index.html

<?php
require 'vendor/autoload.php';

use PostgreSQLTutorial\Connection as Connection;
use PostgreSQLTutorial\CustomerDB as CustomerDB;

try {
    $pdo = Connection::get()->connect();
    // $pagenum = $_GET['pagenum'];
    // $pagesize = $_GET['pagesize'];
    // $start = $pagenum * $pagesize;
    $customerDB = new CustomerDB($pdo);
    $customers = $customerDB->findCustomer(10, 1);
    $arr = json_decode($customers, true);
    // echo $arr["TotalRows"]; 
} catch (\PDOException $e) {
    echo $e->getMessage();
}
?>
Robin
  • 3
  • 5
  • [Hope it will help you](https://stackoverflow.com/questions/4687208/using-htaccess-to-make-all-html-pages-to-run-as-php-files) – Alive to die - Anant Feb 06 '21 at 06:23
  • @AlivetoDie Hmm but mine is reverse. I need PHP to HTML whereas that question is for HTML to PHP – Robin Feb 06 '21 at 06:35
  • What is the purpose of this? The PHP extension is what tells the web server to run the PHP interpreter on the file. If the PHP extension is not present then the PHP code won't run. You can configure the web server to run the PHP interpreter on .html files but all you're getting is a PHP file with a different extension, and a puzzled developer who has to maintain this after you've moved on. Don't do it. – Tangentially Perpendicular Feb 06 '21 at 06:46
  • As per your question: _**Is it possible to place PHP logic that connects to a database into HTMl?For example, I have the following index.php which has HTML in it however I will like to do the reverse where I have index.html and have PHP in it.**_. I have given you correct thread to look at – Alive to die - Anant Feb 06 '21 at 06:51
  • If you want that an HTML can have PHP code in it and will be treated like PHP then you have to go with the thread answer what I have suggested to you. No other option. – Alive to die - Anant Feb 06 '21 at 06:54

0 Answers0