Web Design and Programming Pt 16

MySQL LogoIn this video tutorial I show you the many ways to insert information into MySQL. I specifically show you how to enter the information:

  • Directly through the MySQL shell
  • Through PHP code
  • From a CSV file

I then go into some other basic queries you need to understand to use MySQL. All of the code used follows the video.

If you have any questions or comments leave them below.

Code from the Video

<html>
<head>
<title>Access Database</title>
</head>
<body>
<?php
DEFINE (‘DBUSER’, ‘mysqladm’);
DEFINE (‘DBPW’, ‘Turtle2Dove’);
DEFINE (‘DBHOST’, ‘localhost’);
DEFINE (‘DBNAME’, ‘customer’);
if ($dbc = mysql_connect (DBHOST, DBUSER, DBPW))
{
if (!mysql_select_db (DBNAME))
{
trigger_error(“Couldn’t select database<br />MySQL Error: ” . mysql_error());
exit();
}
} else {
trigger_error(“Could not connect to MySQL<br />MySQL Error: ” . mysql_error());
exit();
}
$file = fopen(‘manu_type_data.csv’, ‘r’);
while(($info = fgetcsv($file, 1000, ‘,’)) != FALSE)
{
$getdata = implode(“,”, $info);
$query = “INSERT INTO manufacturer (man_id,manufact_name) VALUES (” . $getdata . “)”;
echo $query . “<br />”;
$result = mysql_query($query) or trigger_error(“Query<br />MySQL Error: ” . mysql_error());
}
mysql_close();
?>
</body>
</html>

2 thoughts on “Web Design and Programming Pt 16”

Leave a Reply

Your email address will not be published. Required fields are marked *