Your SlideShare is downloading. ×
MySQL Record Operations
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Saving this for later?

Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime - even offline.

Text the download link to your phone

Standard text messaging rates apply

MySQL Record Operations

378
views

Published on

Published in: Technology

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
378
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
26
Comments
0
Likes
0
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide

Transcript

  • 1. MySQL Record OperationsJamshid HashimiTrainer, Cresco Solutionhttp://www.jamshidhashimi.comjamshid@netlinks.af@jamshidhashimiajamshidhashimiAfghanistan WorkforceDevelopment Program
  • 2. Agenda• MySQLi Introduction• mysqli() Overview• mysqli Methods and Properties• INSERT, UPDATE & DELETE• mysqli Prepared Statements• Inserting, Updating and Deleting Records• Managing Data
  • 3. 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.
  • 4. 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
  • 5. MySQLi Introduction• mysql_query() – Deprecated!
  • 6. 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”]);}
  • 7. 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”]);
  • 8. 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);}
  • 9. 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.
  • 10. 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,...)
  • 11. UPDATE• The UPDATE statement is used to modify datain a table.• Syntax:UPDATE table_nameSET column1=value, column2=value2,...WHERE some_column=some_value
  • 12. DELETE• The DELETE statement is used to deleterecords in a table.• Syntax:DELETE FROM table_nameWHERE some_column = some_value
  • 13. Prepared Statements• Prepared statements provide developers withthe ability to create queries that are moresecure, have better performance, and aremore convenient to write.
  • 14. 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();
  • 15. Managing Data
  • 16. DEMO
  • 17. QUESTIONS?