Hello everyone and all the programmers in the world. Today, I will gonna show you a different way of PHP programming using class.php and class. I include in this tutorial some basic way to code your PHP programs. Lets start.
How to connect PHP to MySQL server using class.php
Connect using traditional PHP coding
<?php
$host = "your hosting";
$user = "MySQL username";
$pass = "MySQL password";
$conn = @mysql_connect($host, $user, $pass);
if (!$conn) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db($dbase, $conn);
?>
Connect using class.php and class
<?php
include 'class.php';
$class=new main;
$class->database_connect("your host", 'username", "password", "database name");
?>
The class.php is the source of your code and the functions build on it. Make sure you download class.php and include it into the folder where your index is located. The code $class=main; will tell the computer that you wanna include the main class of class.php.
Replace the host with your hosting name, the username is the MySQL server username and, password is also the password of your MySQL server and lastly is the database name is the name of the database you created.
Coding system with class.php is more simple and easy to understand. Make sure that you always put this code on the top of your code.
How to retrieved information from MySQL to PHP
I made a simple code that is very easy to understand. Retreiving information from MySQL Server to PHP is a process where information from database can be use to display in HTML form. Lets add the code here
<?php
include 'class.php';
$class=new main;
$class->database_connect("your host", 'username", "password", "database name");
$fetch = $class->sql_query("enter your mysql query here");
while($row = mysql_fetch_assoc($fetch)){
echo $row["field name"];
}
?>
You should create a MySQL query and place it in $class->sql_query("enter your mysql query here") and the $row["field name"] displays the information from MySQL to html.
I can give you the class.php for free. Just send your email address in the comment below.
Tomorrow I will discuss how to retrieve information from MySQL to PHP.
Thank you for the contribution. First tag should be "utopian-io" and second one should be tutorials, with a "s". Unfortunately your tutorial will not be approved as Utopian demands high quality work and longer tutorials. You have just explained one concept which is not good. Kindly remove all the unnecessary usernames from the post and try to make longer tutorials next time.
Utopian Helper
Where are you bro
hamhanzala@gmail.com
yahoooo ... I finally get in steemit a well explained class