Your SlideShare is downloading. ×
0
MySQL Record OperationsJamshid HashimiTrainer, Cresco Solutionhttp://www.jamshidhashimi.comjamshid@netlinks.af@jamshidhash...
Agenda• MySQLi Introduction• mysqli() Overview• mysqli Methods and Properties• INSERT, UPDATE & DELETE• mysqli Prepared St...
MySQLi Introduction• MySQLi, often called MySQL Improved, hasseveral advantages over regular MySQL,including support for p...
MySQLi Introduction• The mysqli extension has a number ofbenefits, the key enhancements over themysql extension being:– Ob...
MySQLi Introduction• mysql_query() – Deprecated!
MySQLi• mysqli_fetch_assoc (fetch_assoc())– Fetch a result row as an associative array/* fetch associative array */while (...
MySQLi• mysqli_fetch_array (fetch_array())– Fetch a result row as an associative, a numericarray, or both– MYSQLI_NUM– MYS...
MySQLi• mysqli_fetch_object (fetch_object())– Returns the current row of a result set as anobject/* fetch object array */w...
MySQLi• Do we need to close the connection?– Open connections (and similar resources) areautomatically destroyed at the en...
INSERT• The INSERT INTO statement is used to insertnew records in a table.• Syntax:INSERT INTO table_name (column1, column...
UPDATE• The UPDATE statement is used to modify datain a table.• Syntax:UPDATE table_nameSET column1=value, column2=value2,...
DELETE• The DELETE statement is used to deleterecords in a table.• Syntax:DELETE FROM table_nameWHERE some_column = some_v...
Prepared Statements• Prepared statements provide developers withthe ability to create queries that are moresecure, have be...
Prepared Statementsif($rs = $mysqli->prepare("SELECT first_name FROM actorWHERE first_name = ?")){//binding parameteres$rs...
Managing Data
DEMO
QUESTIONS?
Upcoming SlideShare
Loading in...5
×

MySQL Record Operations

428

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
428
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
27
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Transcript of "MySQL Record Operations"

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

    Clipping is a handy way to collect important slides you want to go back to later.

×