WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDESPHP CLASSESCODE SEARCHARTICLES SEARCHPHP FORUMSPHP MANUALPHP FUNCTIONS LISTWEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Join us on FaceBook
Submit a code Example / Snippet Submit Your Code
Poker Tournaments Poker Tournaments
Poker Guide for Developers Poker Guide for Developers
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Resources
Web Development Content
Internet Security Software
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
פרייסז - הכח לקנות עובר לידיים שלך
Texas Holdem Poker Evangelists

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Specify your connection settings and create a link to a MySQL database.
Categories : PHP, PHP Classes, Databases, MySQL, Beginner Guides Click here to Update Your Picture
Aris Karidis
Date : Nov 29th 2005
Grade : 2 of 5 (graded 5 times)
Viewed : 17277
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Aris Karidis
Action : Grade This Code Example
Tools : My Examples List

Submit your own code examples  Submit your own code examples 
 

<?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
           
}
        }
    }
?>



This class splits the results of the query into multiple pages like what the search engine does.
Categories : PHP Classes, PHP, MySQL, Databases
Create and restore backup of MySQL databases
Categories : MySQL, Databases, PHP, PHP Classes, Complete Programs
SQLite PHP Database Wrapper
Categories : PHP, PHP Classes, Databases, SQLite, Beginner Guides
Newbie Notes #4 - Trapping dumb MySQL query errors
Categories : PHP, Databases, MySQL, Debugging, Beginner Guides
email new items in db
Categories : PHP, Email, Databases, MySQL, Beginner Guides
TAB_STRUCT Class: Is supporting Class for the DBXML Class
Categories : PHP, PHP Classes, MySQL, XML, Databases
MySQL database class
Categories : PHP, MySQL, Databases, PHP Classes
mySQL/PHP/search with multientry form and table output with colored rows
Categories : PHP, Beginner Guides, MySQL, HTML and PHP, Databases
Ajax PHP Tree (Left and Right) with MySQL
Categories : PHP, Databases, MySQL, AJAX, PHP Classes
YellowPages Content Grabber (PHP5 +)
Categories : PHP, PHP Classes, Regexps, Databases, MySQL
Setting up InnoDB on MySQL and using Transactions Begin, Commit, Rollback in PHP.
Categories : PHP Classes, Databases, PHP, MySQL, InnoDB
Link Manager for Link Exchangers
Categories : PHP, PHP Classes, Databases, MySQL, CURL
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
PHP Transfer data from text file to Mysql Table
Categories : PHP, PHP Classes, Filesystem, Databases, MySQL
Sort the results from a SELECT query (any number of columns) into an array automatically.
Categories : PHP, PHP Classes, Arrays, Databases, MySQL
 Joseph Crawford wrote :1366
this code example is pretty much the basics may as well have just used the mysql_ php functions.