Page 1: Setting up MySQL connection class
In this article I will explain how to setup and get the promised MySQL connection class to work. First of all download the php file from here: MySQL Connection class, Password for opening the zip file is: electronicspub.com
If you are going to follow this article by using a Webserver supporting PHP and MySQL, you should be fine. IF not, you can download a nice local server program that contains most of your PHP developing base named XAMPP.
After unzipping the file, you will find a file named mysql.php, Upload it into your server or local driver where your local server can parse php files. usually htdocs if you are using XAMPP.
As we are going to work on a test table, make sure you will have the following table in your MySQL Database, Either you can make this table manually or use a third party software like phpMyAdmin. So first create a database named test (or use an existing database but make sure to change test to your own database name in the provided examples) and then make a table like this:
CREATE TABLE electronicspub ( `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY , `author` VARCHAR( 60 ) NOT NULL , `news` TEXT NULL , `date` DATETIME NOT NULL ) ENGINE = MYISAM ;
After succesfully creating the table, open your editor an make a file named setup.php and include the class (note that it can be in any folder in your webserver or local server, it shouldn't be a problem unless you give the include function a wrong path to the mysql.php file.
<?php //SETUP.PHP //YOUR MySQL CONNECTION DETAILS $DATABASE["server"] = "MYSQL SERVER ADDRESS, default = localhost"; $DATABASE["port"] = "PORT NUMBER, DEFAULT 3306"; $DATABASE["username"] = "DATABASE USERNAME"; $DATABASE["password"] = "DATABASE PASSWORD"; $DATABASE["database"] = "DATABASE NAME"; //Including mysql.php , Remember to give the right path to this file include "mysqlphp"; // Initialaizing connection to database using CLS_MYSQL $_DB = new CLS_MYSQL($DATABASE); //Connecting to database $_DB->Connect(); ?>
So you have intialaized the class by assigning a variable named $_DB.
Now, create another php file (name does not matter, but I make one named test.php), Then it is time to populate our table with some data using this connection class. go to next page!