https://github.com/codeadamca/php-mysql-images-embedded
A basic sample of integrating images into a MySQL database by embedding the images directly into the database. .
https://github.com/codeadamca/php-mysql-images-embedded
mysql php
Last synced: about 4 hours ago
JSON representation
A basic sample of integrating images into a MySQL database by embedding the images directly into the database. .
- Host: GitHub
- URL: https://github.com/codeadamca/php-mysql-images-embedded
- Owner: codeadamca
- Created: 2023-03-18T19:42:42.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2025-01-26T22:10:57.000Z (5 months ago)
- Last Synced: 2025-03-31T07:18:42.935Z (3 months ago)
- Topics: mysql, php
- Language: PHP
- Homepage:
- Size: 1.95 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Using PHP to Display Images from a MySQL Database
A basic sample of integrating images into a MySQL database. In this example the images are added to the links table using binary fields.
## The End Goal
The `links.sql` file in the repository includes a list of social media links and logos that can be imported into your MySQL database. There are no image files in this examples as the images are inside the links table.
There are multiple methods of retrieving data from a MySQL database using PHP. For simplicity sake the example below will use a series of `mysqli` PHP functions.
## Steps
1. Open up phpMyAdmin.
If you're using a local server phpMyAdmin can usually be accessed by starting your server and then clicking on the phpMyAdmin link. If you're using a hosting account there will be a link to phpMyAdmin in your control panel.
Once you have phpMyAdmin open, click on the import tab and select the `links.sql` file from this repository. This will create a table called `links` and populate it with some sample data.
2. Create a new file and name it `index.php`. In that file place the following code:
```php
Adam Thomas
body {
background-color: #000;
}main {
width: 100vw;
height: 100vh;
}video {
z-index: 50;
position: absolute;
object-fit: cover;
width: 100%;
height: 100%;
left: 0;
top: 0;
margin: 0;
opacity: 0.3;
}div {
z-index: 100;
position: relative;
}h1 {
font-family: "PT Sans Narrow",sans-serif;
font-weight: 400;
font-size: 4vmax;
line-height: 4.2vmax;
}h2 {
font-family: "PT Sans Narrow",sans-serif;
font-weight: 400;
font-size: 5vmax;
line-height: 5vmax;
}p {
font-family: "PT Sans Narrow",sans-serif;
font-size: 1.8vmax;
line-height: 2.2vmax;
margin: 3px;
}span {
background-color: #000;
display: inline-block;
padding: 2px 5px;
}
```4. Duplicate `.env.sample` and rename it to `.env`. Update it with your database credentials. You can probably remove the socket information in the `.env` file:
```php
DB_HOST=
DB_DATABASE=
DB_USERNAME=
DB_PASSWORD=
DB_PORT=3306
```
And in the `connect.php` file:
```php
Full tutorial URL:
> https://codeadam.ca/learning/php-mysql-images.html***
## Repo Resources
* [Visual Studio Code](https://code.visualstudio.com/)
* [Filezilla](https://filezilla-project.org/) (or any FTP program)