MySQL Record Operations
Upcoming SlideShare
Loading in...5
×
 

MySQL Record Operations

on

  • 570 views

 

Statistics

Views

Total Views
570
Views on SlideShare
570
Embed Views
0

Actions

Likes
0
Downloads
23
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

MySQL Record Operations MySQL Record Operations Presentation Transcript

  • MySQL Record OperationsJamshid HashimiTrainer, Cresco Solutionhttp://www.jamshidhashimi.comjamshid@netlinks.af@jamshidhashimiajamshidhashimiAfghanistan WorkforceDevelopment Program
  • Agenda• MySQLi Introduction• mysqli() Overview• mysqli Methods and Properties• INSERT, UPDATE & DELETE• mysqli Prepared Statements• Inserting, Updating and Deleting Records• Managing Data
  • MySQLi Introduction• MySQLi, often called MySQL Improved, hasseveral advantages over regular MySQL,including support for prepared statements(which helps prevent SQL injection, a commonsecurity issue) and object-oriented code.
  • MySQLi Introduction• The mysqli extension has a number ofbenefits, the key enhancements over themysql extension being:– Object-oriented interface– Support for Prepared Statements– Support for Multiple Statements– Support for Transactions– Enhanced debugging capabilities– Embedded server support
  • MySQLi Introduction• mysql_query() – Deprecated!
  • MySQLi• mysqli_fetch_assoc (fetch_assoc())– Fetch a result row as an associative array/* fetch associative array */while ($row = $result->fetch_assoc()) {printf ("%s n", $row["Name”]);}
  • MySQLi• mysqli_fetch_array (fetch_array())– Fetch a result row as an associative, a numericarray, or both– MYSQLI_NUM– MYSQLI_ASSOC– MYSQLI_BOTH/* associative array */$row = $result->fetch_array(MYSQLI_ASSOC);printf ("%sn", $row["Name”]);
  • MySQLi• mysqli_fetch_object (fetch_object())– Returns the current row of a result set as anobject/* fetch object array */while ($obj = $result->fetch_object()) {printf ("%s n", $obj->Name);}
  • MySQLi• Do we need to close the connection?– Open connections (and similar resources) areautomatically destroyed at the end of scriptexecution. However, you should still close or freeall connections, result sets and statement handlesas soon as they are no longer required. This willhelp return resources to PHP and MySQL faster.
  • INSERT• The INSERT INTO statement is used to insertnew records in a table.• Syntax:INSERT INTO table_name (column1, column2,column3,...)VALUES (value1, value2, value3,...)
  • UPDATE• The UPDATE statement is used to modify datain a table.• Syntax:UPDATE table_nameSET column1=value, column2=value2,...WHERE some_column=some_value
  • DELETE• The DELETE statement is used to deleterecords in a table.• Syntax:DELETE FROM table_nameWHERE some_column = some_value
  • Prepared Statements• Prepared statements provide developers withthe ability to create queries that are moresecure, have better performance, and aremore convenient to write.
  • Prepared Statementsif($rs = $mysqli->prepare("SELECT first_name FROM actorWHERE first_name = ?")){//binding parameteres$rs->bind_param("s",$name);$name = "BON";//Execute it$rs->execute();//Bind results$rs->bind_result($name);//Fetch records$rs->fetch();printf("%s", $name);$rs->close();}else{echo $mysqli->error;}$mysqli->close();
  • Managing Data
  • DEMO
  • QUESTIONS?