database_functions.php

<?php

/*
    FUNCTION: database_connect();
    
    Opens and returns a database connection on call

    PARAMETERS: $mysql_host    - (call optional as default is set) Defines the server host
                $database_user - (call optional as default is set) Defines the database username
                $user_password - (call optional as default is set) Defines the users password
                $database_name - (call optional as default is set) Defines the database to connect to

*/

function database_connect($mysql_host    'localhost',
                          
$database_user 'pm5494',
                          
$user_password 'X7979642',
                          
$database_name 'pm5494')
{
  
$connection = @mysql_connect ($mysql_host,$database_user$user_password) or die ("Cannot make the connection");
  
//connect to  the database
  
  //Select relevant database
  
@mysql_select_db ($database_name,$connection) or die ("Cannot connect to the database");

return 
$connection;

}

//=============================================================================================



// Function: MySQL Database Connect PDO
// Return a MySQL PDO Object

function PDO_database_connect($host,$user,$dbname,$password){

     try {
       
$PDO_object = new PDO("mysql:host=$host;dbname=$dbname",$user,$password);
       return 
$PDO_object;
     } catch (
PDOException $e) {
       echo 
"Error: ".$e->getMessage();
     }
}

//===========================================================================================


function sanisize_db_out($data){
               
               
// strip slashes
               
$data stripslashes($data);

               
// if the data is a string upper case the first letter.
               
if (is_string($data)){
                 
ucfirst($data);
               }
   return 
$data;
  
}
?>

Paul's Code Library

Categories

Home

AJAX

classes

database_functions

date_functions

file_functions

googlevideo_and_youtube_api

htaccess

image_functions

string_functions