130 likes | 258 Views
End of the Php+MySQL basic part. DAY 10. Prepared by Tanvir Hamid. Things to remember. Establish the connection to Mysql by IP, username, Password Create Database Create Table Insert values Show the values Close the connection. Connection eshtablishment. Connection eshtablish. <?php
E N D
End of the Php+MySQL basic part. DAY 10 Prepared by Tanvir Hamid prepared by Tanvir Hamid
Things to remember • Establish the connection to Mysql by IP, username, Password • Create Database • Create Table • Insert values • Show the values • Close the connection prepared by Tanvir Hamid
Connection eshtablishment Connection eshtablish <?php $con= mysql_connect("localhost",“root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } // Your code here ?> prepared by Tanvir Hamid
Closing a Connection <?php $con = mysql_connect("localhost",“root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } // your code here mysql_close($con); ?> Connection close prepared by Tanvir Hamid
Create Database <?php $con = mysql_connect("localhost",“root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } if (mysql_query("CREATE DATABASE tanvir",$con)) { echo "Database created"; } else { echo "Error creating database: " . mysql_error(); } mysql_close($con); ?> Create the Database named tanvir See exercise 1.php prepared by Tanvir Hamid
After creating database Create Table named data <?php // Create table mysql_select_db(“tanvir", $con); $sql = "CREATE TABLE data ( FirstName varchar(15), LastName varchar(15), Age int )"; // Execute query mysql_query($sql,$con); mysql_close($con); ?> See exercise 1.php prepared by Tanvir Hamid
Inserting values into Table DATA <?php $con = mysql_connect("localhost",“root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db(“tanvir", $con); mysql_query("INSERT INTO data (FirstName, LastName, Age) VALUES (‘Tanvir', ‘Hamid', ‘23')"); mysql_query("INSERT INTO data (FirstName, LastName, Age) VALUES (‘Nurul', ‘Ferdous', ‘28')"); mysql_close($con); ?> See exercise 2.php prepared by Tanvir Hamid
Show the values <?php $con = mysql_connect("localhost",“root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db(“tanvir", $con); $result = mysql_query("SELECT * FROM data"); while($row = mysql_fetch_array($result)) { echo $row['FirstName'] . " " . $row['LastName']; echo "<br />"; } mysql_close($con); ?> See exercise 3.php prepared by Tanvir Hamid
Will work details at day14(Advance MySQL) • mysql_fetch_array(), • mysql_fetch_row(), • mysql_fetch_assoc() Solve the error of your course material book & This is the HomeWork prepared by Tanvir Hamid
Exam will be happened at nest class • About basic php+mySQL • About HTML, CSS • Questions will be formed ZEND style • Lecture sheet and Presentations are enough. • Open book exam prepared by Tanvir Hamid
Open book exam • Remember it will be open book. • But lectures and ppt will not helping you at exam time Bcoz questions will be formed on conceptual and analytical. • NO body run the dream weaver and XAMPP or APACHE. • You will take any kinds of books, ebooks, ppt with you. prepared by Tanvir Hamid
Its not joke…Exam will be Open book. prepared by Tanvir Hamid
Plz turn off ur PC after finish the class prepared by Tanvir Hamid