proscar Posted December 20, 2012 Report Posted December 20, 2012 Hi I would like to connect my shopping cart PHP website on MVC pattern through PDO format, can you help me?
falkencreative Posted December 20, 2012 Report Posted December 20, 2012 Hi I would like to connect my shopping cart PHP website on MVC pattern through PDO format, can you help me? This tutorial has a pretty good overview of PDO and how to use it: http://net.tutsplus.com/tutorials/php/why-you-should-be-using-phps-pdo-for-database-access/
proscar Posted December 21, 2012 Author Report Posted December 21, 2012 Thanks for the reply Now I have the error: Undefined property: PDOStatement::$num_rows for the following: public function get_categories($id = NULL){ $data = array(); if ($id != NULL){ // get specific category if ($stmt = $this->dbh->prepare("SELECT id, name FROM " . $this->db_table . " WHERE id = ? LIMIT 1")){ $stmt->bind_param("i", $id); $stmt->execute(); $stmt->store_result(); $stmt->bind_result($cat_id, $cat_name); $stmt->fetch(); if ($stmt->num_rows > 0){ $data = array('id' => $cat_id, 'name' => $cat_name); } $stmt->close(); } } else { // get all categories if ($result = $this->dbh->query("SELECT * FROM " . $this->db_table . " ORDER BY name")){ if ($result->num_rows > 0){ while ($row = $result->fetch_array()){ $data[] = array('id' => $row['id'], 'name' => $row['name']); } } } } return $data; } How can I sort this out? Thanks
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now