Jump to content

Archive:PHP and MySQL Programming/Database Connectivity: Difference between revisions

From IdeaWazaWiki
No edit summary
wikademia>Ralfe
No edit summary
Line 8: Line 8:
== Opening a Connection to a MySQL Database ==
== Opening a Connection to a MySQL Database ==


 
<?
$db = "database1";
$link = mysql_connect("localhost", "username", "password");
mysql_select_db($db, $link);
?>


== Creating a Query ==
== Creating a Query ==




<?
$query = $mysql_query("SELECT * FROM table1");
?>


== Retrieving data from a SELECT Query ==
== Retrieving data from a SELECT Query ==
Line 20: Line 27:
== Closing a Database Connection ==
== Closing a Database Connection ==


 
<?
mysql_close();
?>


[[Programming:PHP and MySQL:File Handling|<< 3. File Handling]] | [[Programming:PHP and MySQL|TOC]] | [[Programming:PHP and MySQL:Session Handling|>> 6. Session Handling]]
[[Programming:PHP and MySQL:File Handling|<< 3. File Handling]] | [[Programming:PHP and MySQL|TOC]] | [[Programming:PHP and MySQL:Session Handling|>> 6. Session Handling]]

Revision as of 10:17, 21 March 2006

TOC


Introduction

Opening a Connection to a MySQL Database

<?
$db = "database1";
$link = mysql_connect("localhost", "username", "password");
mysql_select_db($db, $link);
?>

Creating a Query

<?
$query = $mysql_query("SELECT * FROM table1");
?>

Retrieving data from a SELECT Query

Closing a Database Connection

<?
mysql_close();
?>

<< 3. File Handling | TOC | >> 6. Session Handling