Go Back   Site Owners Forums - Webmaster Forums > Web Programming > Programming General > PHP / mySQL

Notices


Reply
 
Thread Tools Rate Thread Display Modes
Old 01-29-2012, 11:35 PM   #1
cornerstones
Registered User
 
Join Date: Jan 2012
Location: USA
Posts: 5
How do i connect PHP MySQL to a Database?
__________________

To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts.
cornerstones is offline   Reply With Quote

Old 10-30-2012, 07:31 PM   #2
henryc10
Registered User
 
Join Date: Oct 2012
Posts: 33
first you need to create connection to the database

mysql_connect(servername,username,password);

below is an example we store the connection in a variable ($con) for later use in the script. The "die" part will be executed if the connection fails:

<?php
$con = mysql_connect("localhost","peter","abc123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

// some code

mysql_close($con);
?>

mysql_close above will close the connection automatically when the script ends.
henryc10 is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 

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 Off
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Importance of Php Development for Web Development tech.biztech Programming General 35 11-22-2019 12:37 AM
PHP/ apache problem ncjbhd PHP / mySQL 0 10-17-2011 12:23 AM
is it possible to make an php file trough a php code ncjbhd PHP / mySQL 0 09-21-2011 11:49 PM
Question about using php with dhtml tables wryfhk22 PHP / mySQL 0 09-17-2011 01:59 AM
Integrating PHP question wryfhk22 PHP / mySQL 0 09-08-2011 02:52 AM


All times are GMT -7. The time now is 03:38 AM.


Powered by vBulletin Copyright © 2020 vBulletin Solutions, Inc.