An open API service indexing awesome lists of open source software.

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. .

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;
}




Adam Thomas



php-mysql-images-embedded



https://github.com/codeadamca/php-mysql-images-embedded





```

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)