How can I use this diffrent database function

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Lucnet
Forum Commoner
Posts: 61
Joined: Sat Jun 26, 2004 5:28 pm
Location: Alabama
Contact:

How can I use this diffrent database function

Post by Lucnet »

I am using a simple database funtion, but I don't like the way it is layed out. I have found another databse function that I like from another script. I was wondering how hard would it be for me to use this?

Example of the database code:
Current one:

Code: Select all

<?
function db() {mysql_pconnect("localhost","lsscript","tv781212");mysql_selectdb("lsscript_lstestimonials");
}

function db_close() {
	mysql_close();
}
?>
Example of new one I want to use:

Code: Select all

<?
//-----------------------
        // Database config
        //-----------------------

        // The server your databse is on. This is usually localhost
        $DB_host = "localhost";

        // The username used to access your database
        $DB_user = "";

        // The password used for this username
        $DB_pass = "";

        // The name of the database LS Testimonials is installed on
        $DB_name = "";

        // If you want to add a prefix to the table names. Otherwise
        // leave blank
        $DB_prefix = "lst_";

        // If your database runs under a persistant connection.
        // Note leave this as 0 unless you know what you are doing.
        $DB_pconnect = 0;
?>
Deemo
Forum Contributor
Posts: 418
Joined: Sun Jan 18, 2004 11:48 am
Location: Washington DC

Post by Deemo »

well in the second one, it never actually connects to the database, it just configures it. In the first one, you are configuring it and connecting
User avatar
Lucnet
Forum Commoner
Posts: 61
Joined: Sat Jun 26, 2004 5:28 pm
Location: Alabama
Contact:

Post by Lucnet »

So I wont be able to use it. How hard will it be to get it to work.
User avatar
mikusan
Forum Contributor
Posts: 247
Joined: Thu May 01, 2003 1:48 pm

Post by mikusan »

I think you need to read up on PHP and database connections. The second example you gave us, is just some variable definitions... I personally use arrays, and put them into a config.php and I often include base_dirs and whatnot...

A large 2D array:

Code: Select all

$DB['host'] = 'localhost';
 $DB['user'] = 'mikey';
//.......
As for connecting to the database, just use the standard PHP manual procedure, as it's the best way to start.
When you understand what you are doing I would suggest a database layer, an database class that allows you to use many other databases.

But I suggest you first learn the basics to PHP.

to be nice:
From: http://ch2.php.net/function.mysql-connect

Code: Select all

<?php
$link = mysql_connect($DB['host'],$DB['user'], 'mysql_password');
if (!$link) {

   die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>
Post Reply