3D Gallery with Great Artwork Imagine Logo with Three Colors Beach Cabin 3D Android Tablet with Different Screens Studio Apartment Red Figured Greek Vase on Blue Background Silver and Gold Flashlight Lake on Fire

RESTful Post: MySQL Connection Data

Page 6

HTML, PHP, MySQL

Overview

Create a file with reusable data to connect to your MySQL database and table.

File base-data.php

File base-data.php contains all of the connection data needed to connect to a MySQL database and table, on your server.

Obtain the $hostname, which is a set of digits, from your hosting provider's Website.

$hostname = "012.345.67.89";

The $username field is the name you've chosen through your hosting provider.

$username = "your_name";

The database name is db_test.

$dbname = "db_test";

We chose the name db_test as the name of our test database in the previous section. In the previous section, while creating the database, table and columns, we named the database, db_test.

Your password should always remain private, however we'll need it to connect to the database with PHP, later. Therefore add your password, where the following listing says your_password.

$password="your_password";

The entire base-data.php file follows. However substitute your host name, user name and password values, for the attributes below.

<?php
$hostname = "012.345.67.89";
$username = "your_name";
$dbname = "db_test";
$password="your_password";
?>

Include base-data.php

Create another PHP file named, functions.php. File functions.php will define the functions needed to access and display both posted data and MySQL data. We'll cover each user defined function in detail, later.

Inside functions.php add the following line of code.

include('base-data.php')

Now every function defined within functions.php can access database connection variables stored within base-data.php.

Summary

You created a file, with reusable data, to connect to your MySQL database and table.

Try It!

Try the Post to PHP example described in this tutorial.


Ads >
Create 3D Games: Learn WebGL Book 2 Simple Shaders: Learn WebGL Book 4
3D Programming for Beginners: Learn WebGL Book 1

for Web graphics!

Copyright © 2022 Amy Butler. All Rights Reserved.