It's free and you have access to premium codes!
Welcome back! Please login to your account.
Don't worry, we'll send you a message to help you to recover your acount.
Please check your email for instructions to activate your account.
Written by 21 November 2012
The first step to working with the databases is craeting connection. You can do it within your codes, but professional programmers handles events by functions. Here is a function to connect to MySQL server. This function returns true in success and false, otherwise. It also has capability to print the success or failure message. Enjoy!
<!-- this script is provided by https://www.phpfreecode.com coded by: Kerixa Inc. -->
<!-- This Script is from www.phpfreecpde.com, Coded by: Kerixa Inc-->
<?php
if (DbConnect('localhost','root','')) echo ('
<p style="text-align: center; font-size: 20pt; color: #000000">Continue your
Coding . . .</p>
');
function DbConnect($host,$user,$pass){
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$link=mysql_connect($host, $username, $password);
if(!$link){
echo('
<p style="text-align: center; font-size: 20pt;"><span style="color: #FF0000;">Failed to connect to the database! </span>
<br><span style="font-size: 12pt;">>>Please check the parameters and database server<<</span></p>
');
return false;
}else {
echo('
<p style="text-align: center; font-size: 20pt; color: #1CB00E">Connecting to
the Database was Successful!</p>
');
return true;
}}
;
?>
<br style="font-size: 8pt"><font face="Tahoma"><a target="_blank" href="http://www.phpfreecode.com/"><span style="font-size: 8pt; text-decoration: none">PHP Free Code</span></a></font></div>
<a target='_blank' href='https://www.phpfreecode.com' style='font-size: 8pt; text-decoration: none'>Php Best Codes</a>
Comments
Here you can leave us commments. Let us know what you think about this code tutorial!