1

I get the error in the title when working on portfolio of pset7.

I went into a sql shell as described here and the table portfolio appears in the list - if it didn't appear in the list, I could have followed the instructions in that post.

As requested - the output from mysql50 shell

~/workspace/ $ mysql50 shell
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 67
Server version: 5.5.46-0ubuntu0.14.04.2 (Ubuntu)

Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| phpmyadmin         |
| pset7              |
+--------------------+
5 rows in set (0.01 sec)

mysql> USE `pset7`;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
mysql> SHOW TABLES;
+-----------------+
| Tables_in_pset7 |
+-----------------+
| portfolios      |
| users           |
+-----------------+
2 rows in set (0.00 sec)

mysql> exit
Bye
1
  • Additionally, my database looks fine in phpMyAdmin. The database appears to be disconnected only when being called by php. Sep 10 '16 at 18:49
1

I know you said that you have already done this, but please open a new Terminal tab in ide50, and execute the following commands:

mysql50 shell
SHOW DATABASES;
USE `pset7`;
SHOW TABLES;
exit

Then paste the output of this command into your original question, and press Ctrl+K (or click the {} button in the editor) to format as a code block.

This will allow me to verify that your database is really called pset7 and that your table is really called portfolio (not portfolios or Portfolio). If the db name or table name is incorrect, you can easily just change your PHP code to refer to the correct table name.

Hope this helps!

EDIT: Thank you for pasting the mysql50 shell output.

My hunch was absolutely correct: you are using the wrong table name.

Your error message said:

Fatal error: Table 'pset7.portfolio' doesn't exist

But SHOW TABLES; says:

mysql> SHOW TABLES;
+-----------------+
| Tables_in_pset7 |
+-----------------+
| portfolios      |
| users           |
+-----------------+
2 rows in set (0.00 sec)

Do you see the difference?

The PHP error tells me that your PHP code must be looking for a table called portfolio, but that table does not exist in the database pset7.

The table you are looking for is actually called portfolios, not portfolio.

This small difference is crucial!

The computer does not understand that these table names are similar -- it only cares that the table you ask for in your PHP source code and the table that exists in MySQL are exactly identical.

Otherwise, it will not find the table you are looking for, and will complain that it does not exist. Because it doesn't!

There are two ways of dealing with this discrepancy. You can rename the table in MySQL (not recommended) or you can, much more simply, change portfolio to portfolios wherever it occurs in your PHP code (as I have already recommended above).

4
  • A little more information - I did recently change the name of the folder in which I was working. The previous name was "pset7Old". I don't see this name anywhere in the output. Does it matter which folder I start the mysql50 shell? Sep 11 '16 at 13:47
  • You are using the wrong table name, as I suspected. Please see my EDIT above for more information. Hope this helps! Sep 11 '16 at 17:00
  • 1
    Thanks. That was it. Sep 11 '16 at 22:44
  • You're welcome! Sep 11 '16 at 22:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .