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-20-2009, 10:41 AM
edhan's Avatar
WebProWorld Veteran
 
Join Date: Aug 2003
Location: Singapore
Posts: 716
edhan RepRank 3edhan RepRank 3edhan RepRank 3
Default What's wrong with this command?

Hi

I am trying to add additional field in wordpress table, but doesn't seem to work. Can anyone please tell me what's wrong with this command in my file called update.php.

Thanks!

Code:
<?
require('wp-config.php');
//DB_NAME
$notinstalled=false;
$db_wp_connection = mysql_pconnect(DB_HOST, DB_USER, DB_PASSWORD) or trigger_error(mysql_error(),E_USER_ERROR);

mysql_select_db($database_name, $db_wp_connection);

	$sql = "ALTER TABLE wp_posts ADD post_category INT (4) NOT NULL AFTER post_title";


?>
Reply With Quote
  #2 (permalink)  
Old 07-20-2009, 10:58 AM
kgun's Avatar
WebProWorld 1,000+ Club
WebProWorld MVP
 
Join Date: May 2005
Location: Norway
Posts: 5,705
kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9
Default Re: What's wrong with this command?

I am a little away from SQL now, but

have you tried the command from SQL command level?

Just wondering: Should it be

... ADD COLUMN ...
Reply With Quote
  #3 (permalink)  
Old 07-20-2009, 11:09 AM
edhan's Avatar
WebProWorld Veteran
 
Join Date: Aug 2003
Location: Singapore
Posts: 716
edhan RepRank 3edhan RepRank 3edhan RepRank 3
Question Re: What's wrong with this command?

Quote:
Originally Posted by kgun View Post
I am a little away from SQL now, but

have you tried the command from SQL command level?

Just wondering: Should it be

... ADD COLUMN ...
post_category is the column I want to add after the post_title. I have done it in phpMyAdmin and it works. But I have alot of wordpress blogs to update so thinking of just writing a small php file where it will be easier to update them. I still can't figure out where I went wrong. arrrgghhhh ...

SOLVED:

Change the command to be like this:

Code:
<?
require('wp-config.php');
$db_wp_connection = mysql_pconnect(DB_HOST, DB_USER, DB_PASSWORD) or trigger_error(mysql_error(),E_USER_ERROR);

$database_name=DB_NAME;

mysql_select_db($database_name, $db_wp_connection);
$p_sql="select * from wp.posts";
$rs_table = mysql_query($p_sql, $db_wp_connection);
	$sq = "ALTER TABLE wp_posts ADD post_category INT (4) NOT NULL AFTER post_title";

mysql_query($sq) or die(mysql_error()." (script line: ".__LINE__.")");
?>

Last edited by edhan; 07-20-2009 at 11:18 AM.
Reply With Quote
  #4 (permalink)  
Old 07-20-2009, 11:13 AM
Biggles's Avatar
WebProWorld Member
 
Join Date: Aug 2004
Posts: 68
Biggles RepRank 1
Default Re: What's wrong with this command?

I am not familiar with wordpress and am not sure if it is covered in your code somewhere else... but where is the $sql variable actually being sent to MySQL ?

maybe it's not the $sql but the call to the db thats failing?
Reply With Quote
  #5 (permalink)  
Old 07-20-2009, 11:14 AM
kgun's Avatar
WebProWorld 1,000+ Club
WebProWorld MVP
 
Join Date: May 2005
Location: Norway
Posts: 5,705
kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9kgun RepRank 9
Default Re: What's wrong with this command?

Another question INT (4) or INT(4) ?
Reply With Quote
  #6 (permalink)  
Old 07-20-2009, 11:20 AM
edhan's Avatar
WebProWorld Veteran
 
Join Date: Aug 2003
Location: Singapore
Posts: 716
edhan RepRank 3edhan RepRank 3edhan RepRank 3
Default Re: What's wrong with this command?

Thanks for your reply. I have solved it. You can see the code in previous reply.

I just copied it somewhere for one of the installations and this works!
Reply With Quote
  #7 (permalink)  
Old 07-21-2009, 12:31 AM
Steelchord's Avatar
WebProWorld Member
 
Join Date: Nov 2005
Location: Tampa, FL
Posts: 31
Steelchord RepRank 1
Default Re: What's wrong with this command?

Yep, it did strike me that the $database_name and $db_wp_connection variables weren't necessarily set with anything useful. I'm glad you got this one solved.
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
Wrong Keyword, Wrong Site leading to Wrong Traffic: Please Advice adeelkhero Google Discussion Forum 19 07-14-2008 10:08 PM
Auto Run Command Question sduquette IT Discussion Forum 1 04-15-2005 02:29 PM
link: command paranoia magnolia1 Google Discussion Forum 3 12-14-2004 08:20 AM
Using Fdisk command cecilia78 IT Discussion Forum 5 12-08-2004 11:41 PM
AltaVista's link: command Will.Spencer Search Engine Optimization Forum 1 07-03-2004 02:29 AM


All times are GMT -4. The time now is 10:56 PM.



Search Engine Optimization by vBSEO 3.3.0