please update your code with pastebin, so we can have an idea.
i have a custom table that is written/read/deleted to with:
$wpdb->insert( wp_custom_table, $entry);
$wpdb->query ('SELECT * FROM wp_custom_table');
wp_reset_postdata();
wp_reset_query();
&
$wpdb->query("DELETE FROM wp_custom_table WHERE number = '$number'");
try a different wordpress function, to make sure it is loading properly. get the current logged in user or echo the site name or something.
yes.
i would try some very simple implementations like i have above, to verify table name is correct and all.
you have : wp_gbsavingsclub.wp_access_codes
doesn’t that tell it to look in a db named gbsavingsclub for the table wp_access_codes? in my setup as you can see, it’s just the table name. i’m pretty sure wpdb defines the db you are working in, and you just define the table.
note that though wpdb uses mysql syntax you can’t use just any mysql query.
Yes, this code also talkes to another database so I explicitly told it to use that database to rule out any conflict. I’ve tried all the WP syntax conventions and absolutly no query at all will run.
I tried the WP convention $wpdb->access_codes
I added the new table to the db.php file
I copied the code into the SQL prompt inside the database and ran it – replacing the vaiable of course, and it runs fine, even with the naming convention I have in the code as you see it.
I tried to use the porper WP SQL $wpdb->insert(table, array(col=> value)
I tried to use $wpdb->get_var(select…)
I read this over and over http://codex.wordpress.org/Class_Reference/wpdb
The queries just NEVER execute. The SELECT checks the table for the variable … I entered it in the database myself and it still evealuated as if it wasn’t in the database so I know even the SELECT isn’t running.
The insert is in both places just so it run, until I get it working.
Queries just aren’t working though the rest of the registration function executes.
It’s really weird. I’ve been trying for 6 hours easy on what is supposed to be a simple thing lol
that code may use 2 dbs but wordpress doesn’t, does it? you can only use wpdb to mess with the db that wordpress runs off of, for any others you need to use mysql statements.
so if the table name is “wp_access_codes” , (and it should have the wp_ in the front, visible from phpmyadmin for example)
then run:
$wpdb->query ('SELECT * FROM wp_access_codes');
while ($n <= $wpdb->num_rows) {
$entry = $wpdb->get_row('SELECT * FROM wp_driver_alerts', ARRAY_A, $n);
echo 'entry #'. $n. ' = '. $entry. '<br />';
$n++;
it should print everything in the table. if not, you are not calling the table correctly (the name is wrong, you’re specifying the db, etc)
make sure to:
require_once('/wp-load.php');
with whatever relative location it’s in
Yes, this one installation actually talks to two different databases using the naming convention I have in my code databasename(DOT)tablename. Normal MySQL. Should work. wp_ is visible in phpmyadmin – I kinda live in a database lol and PHP is my favorite, so not exactly an amature – but sure feeling like it now lol
I’ll try your code snippet and see what’ts up.
Thanks!
yeah i use mysql whenever i need a db but php is where it’s at for me 🙂
i can tell you know, as your syntax was correct. i didn’t even know wp could run off two db, i need that for a project so now have something to learn 🙂
try running a straight mysql statement? obviously it should work but sometimes going back farther than necessary triggers the solution in my mind.