Support Forums
[TUT] Include mySQL into php. - Printable Version

+- Support Forums (https://www.supportforums.net)
+-- Forum: Categories (https://www.supportforums.net/forumdisplay.php?fid=87)
+--- Forum: Coding Support Forums (https://www.supportforums.net/forumdisplay.php?fid=18)
+---- Forum: Database Programming (https://www.supportforums.net/forumdisplay.php?fid=28)
+---- Thread: [TUT] Include mySQL into php. (/showthread.php?tid=116)

Pages: 1 2 3 4 5


[TUT] Include mySQL into php. - MyNameIs940 - 10-04-2009

Make a settings.inc.php and put this in there:

(CHMOD should be: 755)
PHP Code:
<?
        $CONFIG
['DBHOST'] = "localhost"// Database servers location, normally localhost
        
$CONFIG['DBUSER'] = "username"// sql user
        
$CONFIG['DBPASS'] = "password"// db users password
        
$CONFIG['DBNAME'] = "database"// Database to connect to
?>

then make database.php

(CHMOD should be: 644)
PHP Code:
<?
        
include("settings.inc.php");
        
$connection mysql_connect($CONFIG['DBHOST'],
        
$CONFIG['DBUSER'],
        
$CONFIG['DBPASS']) or die("Could not establish a connection with mysql.");
        
mysql_select_db($CONFIG['DBNAME']) or die("Unable to select database.");
?>

Then in all your codes put:

PHP Code:
<? include("database.php"); ?>

You are done Big Grin


Note: If you need help with CHMOD visit this link: http://www.supportforums.net/showthread.php?tid=182


RE: [TUT] Include mySQL into php. - FBI - 10-05-2009

Thats simple enough,
So, what CHMOD should implement on both files to securing? Smile


RE: [TUT] Include mySQL into php. - MyNameIs940 - 10-05-2009

Good idea, I shall add that into the tut once I get home.


EDIT: added it.


RE: [TUT] Include mySQL into php. - xiofire - 10-05-2009

Hmm... Shorthand? Yuck.
Heres how I connect to my databases

Code:
<?php
class connection {
    private $database, $connect;
    function connect() {
        $this->database = array(
        'username' => 'USERNAME',
        'password' => 'PASSWORD',
        'host' => 'localhost',
        'name' => 'DATABASE NAME'
        );

        $this->connect = mysql_connect($this->database['host'], $this->database['username'], $this->database['password']);
        mysql_select_db($this->database['name'], $this->connect);
    }
}

$db = new connection();
$db->connect();
?>



RE: [TUT] Include mySQL into php. - immi - 10-06-2009

(10-05-2009, 05:30 PM)xiofire Wrote: Hmm... Shorthand? Yuck.
Heres how I connect to my databases

Code:
<?php
class connection {
    private $database, $connect;
    function connect() {
        $this->database = array(
        'username' => 'USERNAME',
        'password' => 'PASSWORD',
        'host' => 'localhost',
        'name' => 'DATABASE NAME'
        );

        $this->connect = mysql_connect($this->database['host'], $this->database['username'], $this->database['password']);
        mysql_select_db($this->database['name'], $this->connect);
    }
}

$db = new connection();
$db->connect();
?>

Correct, simple and easy enough.. Good work ;)


RE: [TUT] Include mySQL into php. - xiofire - 10-06-2009

(10-06-2009, 08:48 AM)immi Wrote: Correct, simple and easy enough.. Good work ;)
Thank ya, I take pride in my PHP Tongue


RE: [TUT] Include mySQL into php. - GizSho - 10-07-2009

Both methods work, nice tutorial.


RE: [TUT] Include mySQL into php. - flAmingw0rm - 10-08-2009

Thanks for the great tutorial, worked well.


RE: [TUT] Include mySQL into php. - El Zorro - 10-08-2009

yeah both methods work


RE: [TUT] Include mySQL into php. - HuNt3R - 10-08-2009

Very nice TUT, this will help out alot of members