unknowncheats uc-forum.com ucdownloads ucdownloads.com

Go Back   UC-Tutorials - Multiplayer Game Hacking and Cheat Tutorials > Web / Scripting > PHP

- Sponsored Advertisement -
http://www.myfpscheats.com/


Reply
 
Thread Tools Display Modes
  #1  
Old 12-23-2006, 07:49 AM
zero_tolerance zero_tolerance is offline
Senior Member
 
Join Date: Dec 2006
Posts: 289
Default NeMSeR's Tutorials - Connecting to a mysql database

By NeMSeR

NeMSeR's Tutorials
- Connecting to a mysql database -




Rrrrrright then.

In this tutorial i will be showing you how to connect to a mysql database using php.

First of all we need a mysql database! If you don't know how to do that then learn and come back :P

Now the fun begins.

Now, to make things alot easier we shall put the connection stuff into a seperate file called connect.php, this way we can include it into any page we want without writing it all out on seperate pages. This is what the connect.php should look like.

PHP Code:
$dbhost 'localhost'// This is the ip of the server your database is at.
$dbuser 'user_name'// This is the username of the database.
$dbpass 'password'// This is the password used with the username to access the database.
$dbname 'database_name'// This is the name of the database. 
You don't have to use these variables, you can use anything you want like $gayhost or i dunno lol.

Ok now we connect.

PHP Code:
$connect mysql_connect($dbhost$dbuser$dbpass) or die('You\'ve done something wrong god damnit'); 
This will connect to the database and if you've done it wrong for some weird reason, it will display "You've done something wrong god damnit".

But it doesn't know what database to use?! Well stop being so clever and read this part.

Now we select the database using this.

PHP Code:
mysql_select_db($dbname) or die('Couldn\'t select the database, go back to pen and paper'); 
Now save that to connect.php, so it should look like this! I'll just use random things for the account.

PHP Code:
<?php

$dbhost 
'localhost';
$dbuser 'shootsgay';
$dbpass 'shootlikesass';
$dbname 'eleethalismywhore';

$connect mysql_connect($dbhost$dbuser$dbpass) or die('omfg');

mysql_select_db($dbname) or die('har har you got punned');

?>
See! that wasn't too hard to connect to a database now was it?!?!

In my next tutorial i will be showing you how to add data to the database, delete data, edit data and even withdraw it and display it on a page!

+rep if you found this tutorial handy, if you need anything explained then please reply to this thread.
Reply With Quote
Reply

  • Submit Thread to Digg
  • Submit Thread to del.icio.us
  • Submit Thread to StumbleUpon
  • Submit Thread to Google
  • Submit Thread to Facebook
  • Submit Thread to My Yahoo!
  • Submit Thread to MySpace
  • Submit Thread to Twitter
  • Submit Thread to Reddit

Tags
connecting, database, mysql, nemser, tutorials

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



All times are GMT. The time now is 03:42 PM.