Click here to Skip to main content
15,913,722 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how to create a function my php database connection
Posted

Create a file called "Conn.php" with the following sample code, this code connects
to the localhost with username (user1), password (password1), database name (test)

PHP
<?php
    $conn = mysql_connect('localhost','user1','password1');
    if(!$conn) die("Failed to connect to database!");

    $conencted = mysql_select_db('test', $conn);
    if(!$conencted) die("Failed to select database!");
?>


Use this as an include file on the pages where you wants to use the connection for querying the database.

Hope this helps
 
Share this answer
 
Please be more specific with description of your problem.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900