iEntry 10th Anniversary Forum Rules Search
WebProWorld
Register FAQ Calendar Mark Forums Read
Database Discussion Forum This is the place to find help resolving those nagging questions you have about implementing and using all kinds of databases. Need help writing a query? Need an opinion on Oracle? Post here!

Share Thread: & Tags

Share Thread:

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 07-26-2009, 12:19 AM
edhan's Avatar
WebProWorld Veteran
 
Join Date: Aug 2003
Location: Singapore
Posts: 716
edhan RepRank 3edhan RepRank 3edhan RepRank 3
Question Why the database unable to create?

Hi

I am trying to create a table in wordpress blog but it does not seem to be able to do so. Wondering if anyone can tell me what is wrong with this code. Thanks!

Code:
function sa_install(){
   global $table_prefix, $wpdb, $user_level;

   $table_name = $table_prefix . "record_display";

   if($wpdb->get_var("show tables like '$table_name'") != $table_name){

   $sql = "CREATE TABLE ".$table_name." (
   id mediumint(9) NOT NULL auto_increment,
   record_id int(11) NOT NULL default '0',
   record_display text NOT NULL,
   record_description text,
   PRIMARY KEY  (`id`)
   );";
Reply With Quote
  #2 (permalink)  
Old 07-26-2009, 12:51 AM
wige's Avatar
Moderator
WebProWorld Moderator
 
Join Date: Jun 2006
Location: United States
Posts: 2,648
wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9wige RepRank 9
Default Re: Why the database unable to create?

Try adding the following:

$results=mysql_query($query);
if ($results) {
echo "yay";
} else {
echo mysql_error();
}

My guess would be that the user your PHP script uses to access the database doesn't have CREATE permissions on the database, which is common since this could be a security issue.
__________________
The best way to learn anything, is to question everything.
Reply With Quote
  #3 (permalink)  
Old 07-26-2009, 12:59 AM
edhan's Avatar
WebProWorld Veteran
 
Join Date: Aug 2003
Location: Singapore
Posts: 716
edhan RepRank 3edhan RepRank 3edhan RepRank 3
Default Re: Why the database unable to create?

Hi wige

I have added that as you have said, it doesn't give me the echo or the error. Check the database using phpMyAdmin, the table is not created.

Just letting you know that it is activated in the wordpress plugin. Might be why it did not show the echo yay when activated.

Update:

When I went to the plugin configuration, it shows:
The database table is not installed, check your db permissions and activate the plugin again or run the following code in phpMyAdmin

How to I change the db permission? As I will be using alot of this plugin, I do not want to manually add the code in phpMyAdmin.

Last edited by edhan; 07-26-2009 at 01:06 AM.
Reply With Quote
  #4 (permalink)  
Old 07-28-2009, 03:49 AM
edhan's Avatar
WebProWorld Veteran
 
Join Date: Aug 2003
Location: Singapore
Posts: 716
edhan RepRank 3edhan RepRank 3edhan RepRank 3
Default Re: Why the database unable to create? SOLVED

Hi

Just letting you know that I have resolved this issue and here is how I have solved the mystery. I just need to add the command to access the database (wp-config.php in wordpress) and it works.
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Database Discussion Forum

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Unable to subscribe to threads Clint1 WebProWorld: Guidelines/Announcements/Suggestions 8 05-05-2009 06:01 PM
Looking for software to create a searchable photo database for a site yougottakickalittle Database Discussion Forum 3 09-19-2007 02:23 PM
Unable to upgrade PHP fizzlesquirt IT Discussion Forum 3 03-21-2005 03:14 PM
What is the best way to create an articles database? sbeco Database Discussion Forum 2 11-24-2004 07:33 PM
What is the best way to create an articles database? sbeco Marketing Strategies Discussion Forum 24 11-06-2004 12:06 AM


All times are GMT -4. The time now is 04:03 PM.



Search Engine Optimization by vBSEO 3.3.0