Welcome!

Join our community of MMO enthusiasts and game developers! By registering, you'll gain access to discussions on the latest developments in MMO server files and collaborate with like-minded individuals. Join us today and unlock the potential of MMO server development!

Join Today!

[PHP] Connection to Mysql server/database

Newbie Spellweaver
Joined
Mar 8, 2010
Messages
23
Reaction score
1
*This is a C&P of my website im not sure if this is allowed but it will help people and i plan to make a new php tutorial everyday, If its small then it be more.

I havnt got time to add the colours to this aswell but the main version is here:

*I am not advertising my website, I have posted this link to real post to help others see more clearly. I do not create any money for this so i can not use all my time to recolour all of this aswell.

-------------------------------

Hello and welcome to my first tutorial i am going to be posting on here, First of all before you can start with any of the tutorials using php and/or mysql you WILL need xampp
what is a free program that installs multi-programs and services to allow you to use mysql, phpmyadmin, php and also to test your work from your local disk drive.

Now with php you do need to start and end the script using tags as such as in HTML, Its all very basic and simple and anything you need to know with the actual php and mysql will be shown to you in this tutorial.

Now you use the script below to start php:

<?php
Once you have started it you may then enter any of the php you wish to use. When you have finished you then need to end php with:

?>
Now that was very simple wasnt it? Now we can start with the connection to mysql. The code will be below this text.
PHP:
<?php
$con = mysql_connect(“$mysqlhost”,”$mysqlun”,”$mysqlpw”);
if (!$con)
{
die(‘Could not connect: ‘ . mysql_error());
}
mysql_select_db(“$mysqldb”, $con);
?>
Ok yet me explain everything in detail

$con = mysql_connect(“Host“, “Username“, “Password“);
- this allows php to know the host, username and password of the mysql server so that you can connect. Where the text is italic is where the info goes that you change to the correct details
*Black text saying host, username, password is where you would type your server details.
PHP:
if(!$con)
{
//1st code
}
else
{
//2nd code
}
- This allows php to check if something is true or not. If its true it will do once piece of code, If not it will start a diffrent code. (the blue is extra code what can be used but what is not used in this tutorial.

PHP:
mysql_select_db(“Database“, $con);
- This connects the datebase you enter to the mysql server you are connecting to.
*Black text saying database is where you would type your database name.

PHP:
die(“Could not connect“ . mysql_error())
- This kills the rest of the page from loading and also disply a message where the black text is.
*The blue font is an extra for when using mysql to disply the error if there is one.

I think thats done now, If you have any errors or problems please contact me or comment below, Many thanks, Ashley Meah
 
Last edited by a moderator:
Back
Top