GithubHelp home page GithubHelp logo

Comments (3)

nikiedev avatar nikiedev commented on August 29, 2024 1

i tested this code and it kinda work for the count after that i dont think is good practice becuse im a noobie dev but it works

` public function select_count($table)
{
$sql_str = 'SELECT ';

    if (is_array($table))
    {
        if (is_array($table[1]))
        {
            $sql_str .= implode(', ', $table[1]) . ' FROM ';
        }
        else
        {
            $sql_str .= $table[1] . ' FROM ';
        }
        $sql_str .= $this->prefix . $table[0];
    }
    else
    {
        $sql_str .= ' COUNT(*) FROM ' . $this->prefix . $table;
    }

    try
    {
        $this->query = $this->dbh->prepare($sql_str);
        $this->query->execute();
        $res =  $this->query->fetchColumn();
        return $res;
    }
    catch (\PDOException $e)
    {
        error_log($e);

        return false;
    }
}`

//usage
$member = $db->select_count('member');
echo $member;

Thank you for your comment! I also think that there must be better way to do that but i had no time to test all and think a lot about that. I will look that on holidays and unworking functions too.

from simple-php-pdo-database-class.

Francois284Modz avatar Francois284Modz commented on August 29, 2024 1

No problème mate i will try To fix it also

from simple-php-pdo-database-class.

Francois284Modz avatar Francois284Modz commented on August 29, 2024

i tested this code and it kinda work for the count after that i dont think is good practice becuse im a noobie dev but it works

` public function select_count($table)
{
$sql_str = 'SELECT ';

    if (is_array($table))
    {
        if (is_array($table[1]))
        {
            $sql_str .= implode(', ', $table[1]) . ' FROM ';
        }
        else
        {
            $sql_str .= $table[1] . ' FROM ';
        }
        $sql_str .= $this->prefix . $table[0];
    }
    else
    {
        $sql_str .= ' COUNT(*) FROM ' . $this->prefix . $table;
    }

    try
    {
        $this->query = $this->dbh->prepare($sql_str);
        $this->query->execute();
        $res =  $this->query->fetchColumn();
        return $res;
    }
    catch (\PDOException $e)
    {
        error_log($e);

        return false;
    }
}`

//usage
$member = $db->select_count('member');
echo $member;

from simple-php-pdo-database-class.

Related Issues (3)

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.