How to Access Data from WordPress Databases |

How to Access Data from WordPress Databases

This Article will describe how to create and access Data from WordPress Databases. For this purpose, you have at least one user following is the procedure how to do it.

Login to your cPanel and in Database section click on MySQL Database wizard.

 

Enter name of database and click Next Step.

 

Your database is created now in this step set user for database enter details and must remember the password, click Create User.

 

Check the privileges you want to give to user if you want to give full access check ALL PRIVILEGES and click Next Step.

 

User is added to Database now click return to MYSQL Databases.

 

Here you can see your database from here you can rename or delete your database.

 

If you want to change user’s password scroll down and click change password, you can also rename or delete the user as well

 

Now connect your database with your page goto cPanel dashboard in Files section click on file manager.

 

In file manager look for public_html folder.

To create your connection file, click on create +File on left corner.

 

Enter your filename with extension .php and click create new file.

 

Once your file is created right click on it and select Edit.

 

 

Click on edit.

 

This is your editing screen here you will write your connection code.

 

Following is the code how to connect webpage to database, make sure that enter correct details.

<?php

$st=mysqli_connect(‘server name’,’db username’, ‘user password’, ‘databasename’);

If($st)

{

echo “Connected”;

}

else

{

echo “Not Connected”;

}

?>

 

Now to check connection is established or not go to cPanel and look for primary domain.

 

Copy this link and paste in address bar and enter your filename after domain e.g. http://aiitsolutions.com/filename.php and press enter, if it say connected so its mean your connection is established.

 

Now add dummy data into your database for this goto cpanel dashboard , in Databases section  click phpMyAdmin.

 

Now select your database.

 

Enter table name and select how many columns you want then click go.

 

Provide details and click save.

 

Table is created to insert data click in Insert.

 

Enter details and click go.

 

If query will run successfully following message will appear.

 

Now for retrieving data from database to your page go to publicl_html folder and open your page in editor and write code for retrieving data and display it.

<?php

$st=mysqli_connect(‘server name’,’db username’, ‘user password’, ‘databasename’);

If($st)

{

$sql   =” SELECT* FROM exptable”;

$result =myslqi_query($st,$sql);

If(mysqli_num_rows($result)> 0)

{

while($row=mysqli_fetch_assoc($result))

{

echo “id:” .$row[“id”]. “-Name : ”. “ “ . “<br>”;

}

} else

{ echo “0 results”;}

}

else {

echo” Not”;}

?>

 

 

Now you can see your entered data on page.

This how you can create and access Data from WordPress Databases.

You May Also Like

About the Author: Ahmad Latif

Ahmad has 9 years of experience in Graphic design, IT Help-desk and Network Support Agent. He worked with multinational companies to provide IT-solutions/Troubleshoot to end users. He has experience supporting 32 global offices and was a part of the team having offices in Pakistan, Philippines, and India. He has hands-on experience Leading teams, Training Global teams, Incident management, Service desk Projects Management, Virtual Infrastructure Setup/Management, Office365, Window Azure, CISCO IP Phones, Reporting, and many of Adobe products.

Leave a Reply

Your email address will not be published. Required fields are marked *

Share This