It’s not recommended to use reserved words for names in SQL. So I call the count result cnt instead. As your function is scalar, i.e. you expect only one value back, you can use:
$count = $mysqli->query("select count(*) as cnt from cars")->fetch_object()->cnt;
More Related Contents:
- Save the data into a database and return another value from database using PHP
- Commands out of sync; you can’t run this command now
- How to get count of rows in MySQL table using PHP?
- Correct way to use LIKE ‘%{$var}%’ with prepared statements?
- Fatal error: Uncaught exception ‘mysqli_sql_exception’ with message ‘No index used in query/prepared statement’
- You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘WHERE `id` [closed]
- Get table column names in MySQL?
- Example of how to use bind_result vs get_result
- mysqli::query(): Couldn’t fetch mysqli
- How to resolve ambiguous column names when retrieving results?
- mysqli::mysqli(): (HY000/2002): Can’t connect to local MySQL server through socket ‘MySQL’ (2)
- PHP MySQLI Prevent SQL Injection [duplicate]
- Use bound parameter multiple times
- What is the difference between MySQL, MySQLi and PDO? [closed]
- How to test if a MySQL query was successful in modifying database table data?
- mysqli_fetch_array() expects parameter 1 to be mysqli_result, boolean given in [duplicate]
- MySQL “NOT IN” query 3 tables
- Mysql No connection could be made because the target machine actively refused it
- MYSQLi error: User already has more than ‘max_user_connections’ active connections [duplicate]
- How to connect to MySQL database in PHP using mysqli extension?
- Why does this return Resource id #2? [duplicate]
- Fatal error: Call to undefined function mysqli_result()
- How to generate unique id in MySQL?
- Fatal error: Call to undefined method mysqli_stmt::fetch_array() [duplicate]
- How to SELECT DEFAULT value of a field
- mysqli prepared statement num_rows returns 0 while query returns greater than 0 [duplicate]
- Which is fastest in PHP- MySQL or MySQLi?
- UNION syntax in Cakephp
- How do i search from serialize field in mysql database?
- MySqli Commands out of sync; you can’t run this command now [duplicate]