0

I have a custom wordpress table(my_table). And i am inserting,updating all that good stuff to it. When i try to use

$wpdb->get_results("SELECT * FROM $wpdb->my_table",ARRAY_A); 

or

$wpdb->get_results("SELECT * FROM my_table",ARRAY_A); 

I get this error

WordPress database error: [Table 'mydatabase.my_table' doesn't exist]
SELECT * FROM my_table

I have tried to add my_table to wp-db.php as well but i still receive this error.

  1. Yes the table is in the database
  2. There is data in the table

Is their a config option of i need to change or somewhere else where i need to add my table name? I cannot find it for some reason.

full error

WordPress database error Table 'mydatabase.mytable' doesn't exist for query SELECT * FROM mytable made by do_action, call_user_func_array, promos
10
  • Does WordPress have permission to read that table? Commented Dec 7, 2012 at 0:19
  • @Catcall i created the table with the same user that i set for wordpress to use. Commented Dec 7, 2012 at 0:23
  • If mydatabase is WordPress database (to be confirmed by tiggles), then yes, it has permission. It can even create or delete any table in the database. Commented Dec 7, 2012 at 0:23
  • @barakadam It is in the wordpress database Commented Dec 7, 2012 at 0:32
  • And did you try, for example, SELECT * FROM wp_options so you can see if the other WordPress tables are found? Commented Dec 7, 2012 at 0:36

2 Answers 2

1

Ok tiggles, here is what I would do in your situation if you are still stuck. Create a new table, but this time, by executing a SQL command from WordPress, using something like :

$wpdb->query('CREATE TABLE mynewtable (First_Name char(50), Last_Name char(50), ... etc.)');

Immediately check that you can query it. If so, then go to your databse and dump all data from mytable into this newly created table. Use this one instead.

If it was a user permission because the user that created the previous table was not the same as the one granted access to as WordPress, then you will be safe.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes create a table through wordpress worked. Thanks for your help
0

If your table my_table is, indeed, in the mydatabase database and if mydatabase is, indeed, WordPress' database, there is no reason why it should not work. If mydatabase is not WordPress database or if my_table is in another database, then it is normal that it does not work.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.