1 / 5

OO Mysqli

OO Mysqli. Object Orientated mysqli. All the examples so far have used procedural mysqli functions. The mysqli extension also supports an object orientated syntax. This object orientated syntax is often more compact and easier to follow. Connect Object-Orientated. $db = new mysqli (

floria
Download Presentation

OO Mysqli

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. OO Mysqli

  2. Object Orientated mysqli • All the examples so far have used procedural mysqli functions. • The mysqli extension also supports an object orientated syntax. • This object orientated syntax is often more compact and easier to follow.

  3. Connect Object-Orientated $db = new mysqli( 'mysqlsrv.dcs.bbk.ac.uk', 'my_username', 'my_password', 'my_db_name'); /* check connection */ if($db->connect_errno){ exit($db->connect_error); }

  4. Write Query Object-Orientated /* add student */ $sql = "INSERT INTO students VALUES ('Jane',26,'female')"; if(!$db->query($sql)) { exit($db->error); } Table students

  5. Read Query Object-Orientated /* get all students */ $result = $db->query("SELECT name,age FROM students"); /* check query */ if($result === false) { exit($db->error); } /* fetch associative array */ while($row = $result->fetch_assoc()){ echo $row['name'].', '.$row['age'].' yrs old'; } /* free result set */ $result->close(); Table students

More Related