VB icon

Learn MySQL thru PHP! Easily and Quickly! (updated!)

Email
Submitted on: 1/1/2015 5:55:00 AM
By: Piotr Sienkiewicz (from psc cd)  
Level: Beginner
User Rating: By 8 Users
Compatibility: PHP 3.0, PHP 4.0
Views: 871
 
     This code teaches you how to connect and use a MySQL database thru PHP 3/4. Great for beginners! I update it, so the version on this page has no comments because the PSC butchers it alot, so if you would like an explanation of the code go here http://www.moddingcentral.com/~oblivion/ I dont think this is allowed but its for the better. If you want to copy and paste the code then do it thru this the PSC page.
 
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
//**************************************
// for :Learn MySQL thru PHP! Easily and Quickly! (updated!)
//**************************************
You can do whatever you want with this, 
but if you believe it has helped you I 
would appreciate a vote here at PSC
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: Learn MySQL thru PHP! Easily and Quickly! (updated!)
// Description:This code teaches you how to connect and use a MySQL database thru PHP 3/4. Great for beginners! I update it, so the version on this page has no comments because the PSC butchers it alot, so if you would like an explanation of the code go here http://www.moddingcentral.com/~oblivion/ I dont think this is allowed but its for the better. If you want to copy and paste the code then do it thru this the PSC page.
// By: Piotr Sienkiewicz (from psc cd)
//
// Assumes:Learn to use MySQL thru PHP, explains basic PHP functions and introduces you to MySQL statments like INSERT, SELECT, UPDATE, DROP and DELETE and includes error checking
//
// Side Effects:A php 3 or 4 server is required as well as a MySQL database that is accessible to you.
//**************************************

<?php
$connect = mysql_connect('localhost','username','password');
mysql_query("CREATE TABLE table1 (id INT (5) not null , name VARCHAR (32) not null )");
mysql_query("DROP TABLE table1");
mysql_query("CREATE TABLE table1 (id INT (5) not null , name VARCHAR (32) not null )") or die(mysql_error());
mysql_query("INSERT INTO table1 (id, name) VALUES ('1', 'name1')") or die(mysql_error());
mysql_query("INSERT INTO table1 (id, name) VALUES ('2', 'name2')") or die(mysql_error());
mysql_query("INSERT INTO table1 (id, name) VALUES ('3', 'name3')") or die(mysql_error());
mysql_query("INSERT INTO table1 (id, name) VALUES ('4', 'name4')") or die(mysql_error());
mysql_query("INSERT INTO table1 (id, name) VALUES ('5', 'name5')") or die(mysql_error());
$query = mysql_query("SELECT * FROM table1");
$query = mysql_query("SELECT id, name FROM table1");
while($rst = mysql_fetch_array($query)){
	print("$rst[id]<br>$rst[name]<br><br>");
}
$rst = mysql_fetch_array($query);
print("$rst[id]<br>$rst[name]<br><br>");
mysql_query("UPDATE table1 SET name = 'new_name1' WHERE id = '1'") or die(mysql_error());
mysql_query("DELETE FROM table1 WHERE id = '1' AND name = 'name1'") or die(mysql_error());
mysql_query("DELETE FROM table1") or die(mysql_error());
mysql_close();
?>


Other 1 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.