Web app development_crud_13


Published on

Published in: Technology
1 Like
  • Be the first to comment

No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Web app development_crud_13

  1. 1. hasen@microcis.net July 23, 2013Hassen poreya Trainer, Cresco Solution Afghanistan Workforce Development Program CRUD Create, Read, Update, Delete
  2. 2. Requirements  Choice of DBMS - MySQL  Database model (ER - Schema)  GUI – Application program
  3. 3. Functions may be used in CRUD  mysql_connect()  mysql_select_db()  include()  mysql_query()  mysql_fetch_array()  mysql_num_rows()
  4. 4. mysql_connect()  mysql_connect()is designed to handle the connection.  You can use this function internally or you can include it from an external source.  This function takes 3 arguments by default.  host, username, password mysql_connect("localhost","admin", “admin");
  5. 5. mysql_connect()  To check whether the connection is established or not we store this function into a variable and check it with IF statement. <?php $con=mysql_connect("localhost","admin","admin"); if(!$con){ die('Could not connect: ' . mysql_error()); } ?>  You can use this piece of code anywhere in your code anytime, but that’s might be used several times. Then you can put your code in a separate file
  6. 6. mysql_connect() In a Separated File  You code up your connection and db selection into a separate file, then you include that file into the main file. Ex: connect.php contains the connection. <?php .... include („connect.php‟); .... ?>
  7. 7. mysqlSelect_db()  Once you have successfully connected to My SQL, then you must chose a database to work on.  Another PHP fucnction is used to select a database from database server. mysql_select_db(“users”);
  8. 8. Query Conversion  We have SELECT and INSERT queries in Mysql and simply use them during inserting and retrieving. BUT if we want to use them with PHP we must convert them into PHP code.  This conversion is done by a built-in PHP function called mysql_query() mysql_query ("INSERT INTO users (username, password) VALUES ('$uname', '$pword')")
  9. 9. Query Conversion mysql_query("SELECT * FROM users WHERE username= „ahmad'");  When we use SELECT statement, each time it returns one row of a table.  To store the returned data into a variable we must fetch them one by one and store them.  This can be done by a function called  mysql_fetch_array()
  10. 10. Query Conversion $query=mysql_query("SELECT * FROM users WHERE username= „ahmad'");  $result= mysql_fetch_array($query) QueryFetch row by row from queryRecord set
  11. 11. mysql_num_rows()  The mysql_num_rows() function returns the number of rows in a record set.  This function returns FALSE on failure.
  12. 12. Let’s do the practice
  13. 13. hasen@microcis.net July 23, 2013Hassen poreya Trainer, Cresco Solution Any Questions! Afghanistan Workforce Development Program