Jump to content

How To Connect Php Mysql To Database Through Pdo Format


proscar

Recommended Posts

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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...