lecture10 - CPSC431Lecture10 PHP'smysqliExtension...

Info iconThis preview shows pages 1–9. Sign up to view the full content.

View Full Document Right Arrow Icon
    CPSC431 Lecture 10
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
    PHP's mysqli Extension Connecting to the MySQL Server $mysqli = new mysqli("localhost", "siteuser", "secret", "book"); Or $mysqli = new mysqli(); $mysqli->connect("127.0.0.1", "siteuser", "secret", "company"); Selecting a MySQL Database $mysqli->select_db("book") or die("Can't select db!"); Closing a MySQL Connection $mysqli->close();
Background image of page 2
    PHP's mysqli Extension Query Execution <?php $mysqli = new mysqli("127.0.0.1", "siteuser", "secret", "company"); $query = "SELECT productid, name, price FROM product ORDER by name"; $result = $mysqli->query($query, MYSQLI_STORE_RESULT); // Cycle through the result set while(list($productid, $name, $price) = $result->fetch_row()) echo "($productid) $name: $price <br />"; // Free the result set $result->free(); ?>
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
    PHP's mysqli Extension $mysqli->real_query() and $mysqli->store_result() <?php $mysqli = new mysqli(); $mysqli->connect("127.0.0.1", "siteuser", "secret", "company"); $query = "SELECT productid, name, price FROM product ORDER by name"; $mysqli->real_query($query); $result = $mysqli->store_result(); while(list($productid, $name, $price) = $result->fetch_row()) echo "($productid) $name: $price <br />"; $result->free(); ?>
Background image of page 4
    PHP's mysqli Extension $mysqli -> fetch_array() $query = "SELECT productid, name FROM product ORDER BY name"; $result = $mysqli->query($query); while ($row = $result->fetch_array(MYSQLI_ASSOC)) { $name = $row['name']; $productid = $row['productid']; echo "Product: $name ($productid) <br />"; }
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
    PHP's mysqli Extension $mysqli -> fetch_object() $query = "SELECT productid, name, price FROM product ORDER BY name"; $result = $mysqli->query($query); while ($row = $result->fetch_object()) { $name = $row->name; $productid = $row->productid; $price = $row->price; echo "($productid) $name: $price <br />"; }
Background image of page 6
    PHP's mysqli Extension $result->fetch_row() <?php ... $query = "SELECT productid, name FROM product ORDER BY name"; $result = $mysqli->mysqli_query($query); while (list($productid, $name) = $result->fetch_row()) { echo "($productid) $name: $price <br />"; } ... ?>
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
    PHP's mysqli Extension $mysqli->multi_query($query) <?php $mysqli = new mysqli("127.0.0.1", "root", "jason", "company"); // Retrieve the userID from some session ID $userid = $_SESSION['userid']; // Create the queries $query = "SELECT lastname, firstname FROM user WHERE userID='$userid';"; $query .= "SELECT product_count, CONCAT('$',total_cost) FROM
Background image of page 8
Image of page 9
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 11/20/2009 for the course CPSC CPSC431 taught by Professor Prf.wang during the Spring '09 term at CSU Fullerton.

Page1 / 27

lecture10 - CPSC431Lecture10 PHP'smysqliExtension...

This preview shows document pages 1 - 9. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online