Created
December 3, 2012 12:33
-
-
Save de-raaf-media/4194743 to your computer and use it in GitHub Desktop.
simple database operations
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$con = mysql_connect("localhost","peter","abc123"); | |
if (!$con) { | |
die('Could not connect: ' . mysql_error()); | |
} | |
mysql_select_db("my_db", $con) or die(mysql_error()); | |
// insert query | |
mysql_query("INSERT INTO Persons (FirstName, LastName, Age) | |
VALUES ('Peter', 'Griffin',35)") or die(mysql_error()); | |
// update query | |
mysql_query("UPDATE Persons SET Age=36 | |
WHERE FirstName='Peter' AND LastName='Griffin'") or die(mysql_error()); | |
// delete query | |
mysql_query("DELETE FROM Persons WHERE LastName='Griffin'") or die(mysql_error()); | |
// select query | |
$result = mysql_query("SELECT * FROM Persons") or die(mysql_error()); | |
// loop through result | |
while($row = mysql_fetch_array($result)) { | |
echo $row['FirstName'] . " " . $row['LastName']; | |
echo "<br />"; | |
} | |
mysql_close($con); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment