Page 1 of 1

How can I use this diffrent database function

Posted: Thu Jul 15, 2004 12:56 pm
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;
?>

Posted: Thu Jul 15, 2004 12:59 pm
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

Posted: Thu Jul 15, 2004 1:02 pm
by Lucnet
So I wont be able to use it. How hard will it be to get it to work.

Posted: Thu Jul 15, 2004 1:26 pm
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);
?>