Return to Snippet

Revision: 31872
at September 15, 2010 01:04 by paschim


Initial Code
<?php 
//mysql connect

//connect to db and insert
mysql_connect(localhost,$username,$password);
mysql_select_db($database) or die( "Unable to select database");
$query = "INSERT INTO contacts VALUES ('','John','Smith','01234 567890','00112 334455','01234 567891','[email protected]','http://www.gowansnet.com')";
mysql_query($query);
echo "Record added";
mysql_close();




//mysql select query
$result = mysql_query("SELECT id,name FROM table");
if(!$result) {
  echo mysql_error();
}
while($row = mysql_fetch_assoc($result)) {
   echo "Row data: " . $row['id'] . " - " . $row['name'];
}

//alternative select query
mysql_connect(localhost,$username,$password);
mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM contacts";
$result=mysql_query($query);
echo "Data displayed";
mysql_close();


//mysql update
mysql_connect(localhost,$username,$password);
mysql_select_db($database) or die( "Unable to select database");
$query = "UPDATE contacts SET 
							first = '$ud_first', 
							last = '$ud_last', 
							phone = '$ud_phone', 
							mobile = '$ud_mobile', 
							fax = '$ud_fax', 
							email = '$ud_email', 
							web = '$ud_web' 
							WHERE id = '$ud_id'";
mysql_query($query);
echo "Record Updated";
mysql_close();



//delete contact
mysql_connect(localhost,$username,$password);
mysql_select_db($database) or die( "Unable to select database");
$query = "DELETE FROM contacts WHERE id='$id'";
mysql_query($query);
echo "Record Deleted";
mysql_close();


?>

Initial URL

                                

Initial Description

                                

Initial Title
full php mysql connection script

Initial Tags
mysql, php

Initial Language
PHP