Free Web Hosting Forum
Go Back   Free Web Hosting Forum > Website Building > Scripts and Code Snippets
Reload this Page Usefull way to connect to Mysql (include function)
Reply
 
Thread Tools Display Modes
(#1 (permalink))
Old
JPU's Avatar
JPU JPU is offline
Junior Member
JPU is on a distinguished road
 
Posts: 9
Join Date: Jul 2010
Post Usefull way to connect to Mysql (include function) - 07-27-2010, 01:27 AM

First, you will need to make a PHP script with this code
Please modify it to fit your settings
Code:
<?php
 #Modify this with your info
 $sql_localhost='localhost';
 $sql_user_name='root';
 $sql_user_pass='';
 $sql_data_base='test_db';
 #Do not edit this unless you know what you are doing#
 $sql_c=mysql_connect($sql_localhost,$sql_user_name,$sql_user_pass);
 if(!$sql_c) die('Could not Connect:'.$mysql_error());
 $sql_seldb=mysql_select_db($sql_data_base);
 if(!sql_seldb=mysql_select_db) die('Could not connect to database:'.mysql_error());
?>
Name that file above anything you want (EXAMPLE : connect.php)

Now you can simply connect to your database in any php script by just having this code on the php script
Code:
include('connect.php');
NOTE : If you have a file which you create a function, make sure you put this inside the function (EXAMPLE)
Code:
<?php
 include('connect.php');
 function echorandom(){
  include('connect.php');
 }
?>
Reply With Quote
Sponsored Links
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

Forum Jump



Powered by vBulletin® Version 3.8.2
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.5.2
vBulletin Skin developed by: vBStyles.com