I've been working on a website that used to be PHP based. Every file and request was made through PHP, but now I'm passing it all to Angular 14. The only interaction with the database I need is to search a list of file names and their respective authors and creation year.
I want to create this request in an "Angular friendly way", tyring to avoid workarounds...
The current php structure we have looks similar to this:
$connect = new PDO
('dbname','dbname','password');
$author = $_POST['name'];
$title= $_POST['title'];
$year= $_POST['year'];
To select the items:
$sql = $connect->query("select author, title, year, url from files where author LIKE '%$author %' and title LIKE '%$title%' and year LIKE '%$year%' order by author");
The table which is going to display the results of the search:
while ($row = $sql->fetch(PDO::FETCH_ASSOC))
{
echo "<tr>";
echo "<td>".$row['autor']. "</td>";
echo "<td><a href='".$row['url']."' target='_blank'>" .$row['titulo']. "</a></td>";
echo "<td>" .$row['curso']. "</td>";
echo "<td>" .$row['ano']. "</td>";
echo "</tr>";
;
}
echo '</table>';
I'm not necessarily looking forward to get rid of the php code, I'm willing to keep it. I was thinking of using a service to make some kind of subscribe to a post request, as if I was consuming an API.
I was also thinking of getting the data that goes to the table created with "echo" and instead, bind it on a HTML component. I'd subscribe the data to a property on my component.ts file and bind its data on my component.
I'm new at learning how to connect the client side to the database side, so I'd much appreaciate any help or tip on how I could make this request possible. Thanks in advance!