|
|
|
|
|
|
| |
|
<?php
/**
* This class provides methods for setting the
* parameters needed to connect to a MySQL
* database and creates the link to the
* database (mysqli_connect).
*/
class DBSettings
{
private $host; # The name of the server
private $db; # The name of the database
private $user; # The username
private $pass; # The password
private $link; # The mysqli_connect link.
/**
* The class constructor.
*
* @param string $host
* @param string $db
* @param string $user
* @param string $pass
* @return DBSettings
*/
function DBSettings($host, $db, $user, $pass)
{
$this->host = $host; # The name of the server
$this->db = $db; # The name of the DB
$this->user = $user; # The username
$this->pass = $pass; # The password
}
/**
* Creates the link to the database (mysqli_connect).
* The parameter $encrypt specifies if the password
* will be encrypted using the md5 algorythm or not.
* The default value of 1 encrypts the password.
*
* @param numeric $encrypt
* @return object
*/
function dbConnect($encrypt = 1)
{
###############################
### Validate the parameters ###
###############################
if ($encrypt !== 1 && $encrypt !== 0)
{
printf('Invalid parameter for $encrypt. The parameter must be either 1 or 0.');
exit();
}
$host = $this->host;
$db = $this->db;
$user = $this->user;
$pass = $this->pass;
if ($encrypt === 1)
{
$pass = md5($this->pass); # Encrypt the password
}
# Link to the DB
$this->link = mysqli_connect($host, $user, $pass, $db);
if (!$this->link)
{
# Error message if connection fails
printf("Can't connect to the MySQL Database Server.");
exit;
}
else
{
return $this->link; # Return the link
}
}
}
?> | | |
|
| Simple database class Categories : PHP, PHP Classes, MySQL, Databases | | | Link Manager for Link Exchangers Categories : PHP, PHP Classes, Databases, MySQL, CURL | | | PHP Transfer data from text file to Mysql Table Categories : PHP, PHP Classes, Filesystem, Databases, MySQL | | | usercounter class Categories : PHP, PHP Classes, Databases, MySQL, Environment Variables | | | Sort the results from a SELECT query (any number of columns) into an array automatically. Categories : PHP, PHP Classes, Arrays, Databases, MySQL | | | A script to generate a report from a valid mysql connection. The user has to supply which fields he wants to display in table. All properties are changable.
Categories : PHP, PHP Classes, Databases, MySQL, HTML and PHP | | | bookmarker - PHP, PHPLIB, MySQL WWW based bookmark manager Categories : MySQL, PHP, MySQL, Complete Programs, Databases | | | How to Insert a Date Format Into MySQL from PHP Categories : PHP, Databases, MySQL, Date Time, Beginner Guides | | | Newbie Notes #10 - Generating drop downs Categories : PHP, MySQL, HTML, Beginner Guides, Databases | | | Convert SQL from oracle,mysql,mssql,sqlite and odbc to SQL compatible Categories : PHP, PHP Classes, Databases, MySQL, MS SQL Server | | | This program allows you to upload an ODBC ressource - i.e. an MS-Access database to a MySQL server. Categories : Databases, MySQL, Complete Programs, PHP, Databases | | | Simple Mini Poll class library (SimPoll) Categories : PHP, PHP Classes, Databases, MySQL, Complete Programs | | | Making a simple Hit-Log using PHP and MySql Categories : PHP, Log Files, Beginner Guides, Databases, MySQL | | | Powerful php/mysql Pagination for up to 6 URL Params Categories : PHP, PHP Classes, Databases, MySQL, Navigation | | | MySQL Handler Categories : PHP, Databases, MySQL, Classes and Objects, PHP Classes | |
| | | | Joseph Crawford wrote :1366
this code example is pretty much the basics may as well have just used the mysql_ php functions.
| |
|
|