Giter VIP home page Giter VIP logo

Comments (5)

entomb avatar entomb commented on August 26, 2024

Hello @Codez1337 ,

You can use $result->num_rows, it's a property rather than a method but it will hold how many rows the resultset has.

for affected_rows you have the $db->affected_rows() method and you should call right after your query.

example:

$result = $db->query("SELECT * FROM users");
echo $result->num_rows; //how many users


$db->query("DELETE from users WHERE active = 0");
echo $db->affected_rows() //how many rows were deleted;

from obj-mysql.

Codez1337 avatar Codez1337 commented on August 26, 2024

a question which i must ask and may look stupid, but how do you use that in an if statement?

i want to count the rtows and if there are not enough then exit that part of the script. now i know that the old mysql way works but i am trying to get into using classes and oop so how would i do it with this?

I ask because i am getting errors trying to do it the old way.

from obj-mysql.

entomb avatar entomb commented on August 26, 2024

well its quite simple, properties work like variables, actually this num_rows is a direct property from the native php mysqli object.

so you can use it like this

if($result->num_rows==0){
//empty
}

if(!$result->num_rows){
//empty
}

or like this:

if($result->num_rows){
//not empty!
}

from obj-mysql.

Codez1337 avatar Codez1337 commented on August 26, 2024

so the var i name the query becomes an object?

from obj-mysql.

entomb avatar entomb commented on August 26, 2024

@Codez1337 , well, yes, it returns a resultset object that helps you access your data

from obj-mysql.

Related Issues (13)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.