Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7089307
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:54:21+00:00 2026-05-28T07:54:21+00:00

I am new to mysql but have recently tried doing some tutorials to advance

  • 0

I am new to mysql but have recently tried doing some tutorials to advance my knowledge. Anyways I installed mysql on my ubuntu server as well as phpmyadmin. They both seem to work just fine, I created a database in phpmyadmin called “test” as well as a table called “teddy”.
I put data into the table and I can clearly see it through phpmyadmin.

Now when I try accessing this database via a php script on my ubuntu server, nothing happens. Literally nothing. It reacts the same way as if I had a syntax error (a quick load with nothing displayed).

This is my code… If anyone knows where my mistake is it would be much appreciated.

Thank you

 <?php

   $username='root';
    $password='***';
    $database='test';


   @$db= mysqli_connect('localhost', $username, $password, $database);

if (mysqli_connect_errno())
{
echo 'Error: Could not connect';
exit;

 }

 $query= "select * from test";

$result= $db->query($query);

$num_results= $result->num_rows;

echo $num_results;


  ?>

EDITED (based on drew 010)

Problem was the table was not called test but teddy so putting in this code worked.
“SELECT * FROM ‘teddy'”;

$db= new mysqli('localhost', $username, $password, $database);

 if (mysqli_connect_errno())
 {
echo 'Error: Could not connect';
exit;

 }

 $query = "SELECT * FROM 'teddy'";

  $result = $db->query($query);
 if ($result) {
  $num_results = $result->num_rows;

  echo $num_results;
    } else {
  echo "Query failed: {$db->error}\n";
   }


  ?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T07:54:22+00:00Added an answer on May 28, 2026 at 7:54 am

    $result= $db->query($query); is probably returning false for some reason.

    Try:

    $query = "select * from teddy";
    
    $result = $db->query($query);
    if ($result) {
        $num_results = $result->num_rows;
    
        echo $num_results;
    } else {
        echo "Query failed: {$db->error}\n";
    }
    

    See http://www.php.net/manual/en/mysqli.query.php#refsect1-mysqli.query-returnvalues

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am new to MySQL, but I have used Oracle for some time. I
I have just installed Ubuntu. I am a new user to ubuntu but have
I am fairly new to MySQL with Java, but I have executed a few
I have recently switched jobs and at this new company we are using MySQL.
I am somewhat new to MySQL (come from MS SQL) and have recently come
I have succesfully installed mysql-proxy and understood the way working and lua scripting. But
I'm writing an online project asset tracker but I'm new to MySQL. What would
I've done a fair bit of mysql php programming but am pretty new to
I'm not exactly new to PHP but I haven't used MySQL that much, so
I am fairly new to MySQL and have a project in which I need

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.