Your question confuses me a little, however if you come from a php background then you need to understand that AppConnect and Server Connect work differently.
Change your idea from
<?php $path = "whatever" ?>
To
<dmx-value id="your_app_connect_path_variable" dmx-bind:value="/whatever_with_slashes/"></dmx-value>
Change
class="card"><img class="card-img-top" alt="Card image cap" dmx-bind:src="{{your_app_connect_path_variable}}{{image_name_from_your_server_connect_query}}"
So if you only have filenames coming from your database without paths and your paths are a set variable then you will ave a server action with a database connection step, and a database query getting all the image names.
Then in your App Structure in App Connect you will have a Server Connect step running the database query and pulling all the bindings.
Then when you bind the image source you join the path variable and the image name database query together.