Publishing System Settings Logout Login Register
OOP PHP & MySQL Download System
TutorialCommentsThe AuthorReport Tutorial
Tutorial Avatar
Rating
Add to Favorites
Posted on April 20th, 2012
2564 views
PHP Coding
The database connection file

In this file we will be creating the database connection file, so that our code can communication with the database.

First of all, we need to create the database, so simply go into your MySQL Manager (phpMyAdmin maybe?) and create a database and user and allow all of the privaleges then go to the database in phpMyAdmin and click the SQL tab and insert this MySQL Code...

 

CREATE TABLE IF NOT EXISTS `files` (
`id` int(2) NOT NULL AUTO_INCREMENT,
`title` varchar(50) NOT NULL,
`desc` longtext NOT NULL,
`filename` varchar(100) NOT NULL,
`uploaded` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=InnoDBDEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;

CREATE TABLE IF NOT EXISTS `templates` (
`header` longtext NOT NULL,
`footer` longtext NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

INSERT INTO `templates` (`header`, `footer`) VALUES
('rnrnrnrnOOP Download Systemrnrnrnrnrn

OOP Download Systemrn

rn

I developed this little download system, out of boredem. It is mainly for educational purposes.

', '

This system is only for experemental use only, it will not be released to the general public.

rnrn');

Now that we have our database all setup, we can now make the file that connects to the database.

In the dbcon.php file we created earlier simply just put this code in it, its got comments to help you understand what the different parts do.

 

<?php

$dbhost = "localhost"; // this will ususally be 'localhost', but can sometimes differ
$dbname = "dlsys"; // the name of the database that you are going to use for this project
$dbuser = "dlsys"; // the username that you created, or were given, to access your database
$dbpass = "pass"; // the password that you created, or were given, to access your database

mysql_connect($dbhost, $dbuser, $dbpass) or die("MySQL Error: " . mysql_error());
mysql_select_db($dbname) or die("MySQL Error: " . mysql_error());

?>

 

Now you can save this file and move on to the next chapter, The index file.

Next Page
Pages: 1 2 3 4 5
Dig this tutorial?
Thank the author by sending him a few P2L credits!

Send
Andy Rixon

My name is Andy Rixon and I have been into developing PHP and MySQL Application for about 5 years, I am still learning new things everyday.
View Full Profile Add as Friend Send PM
Pixel2Life Home Advanced Search Search Tutorial Index Publish Tutorials Community Forums Web Hosting P2L On Facebook P2L On Twitter P2L Feeds Tutorial Index Publish Tutorials Community Forums Web Hosting P2L On Facebook P2L On Twitter P2L Feeds Pixel2life Homepage Submit a Tutorial Publish a Tutorial Join our Forums P2L Marketplace Advertise on P2L P2L Website Hosting Help and FAQ Topsites Link Exchange P2L RSS Feeds P2L Sitemap Contact Us Privacy Statement Legal P2L Facebook Fanpage Follow us on Twitter P2L Studios Portal P2L Website Hosting Back to Top