Page 1 of 1

Multiple databases

Posted: Sat Feb 10, 2007 5:47 pm
by mpiaser
Weirdan | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I'm hoping somebody can save me the pain of struggling through this one.  I'm trying to copy records from one database to another.  I am able to do this in the MySQL Query Browser but my code in PHP (follows) errors.

Code: Select all

$dbc=@mysql_connect('localhost','CalcUser','dog') or die('ChangeAccountName: bad calcuser password: '.mysql_error());
$junk=mysql_select_db('calculator') or die('Could not select database:'.mysql_error());

$query="'insert into archive.account select * from calculator.account where dateadded<'$ArchiveDate' and PolicyNumber=''";
$result=mysql_query($query) or die('Archive:Insert acount: query='.$query.',error='.mysql_error());
The die result is as follows:

Code: Select all

Archive:Insert acount: query='insert into archive.account select * from calculator.account where dateadded<'2006-10-10' and PolicyNumber='',error=You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''insert into archive.account select * from calculator.account where dateadded<'2' at line 1

Weirdan | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Sat Feb 10, 2007 6:53 pm
by Weirdan
get rid of the single quote (') at the beginning of your query

Multiple database

Posted: Sat Feb 10, 2007 7:10 pm
by mpiaser
Thanks a tons. I didn't see the darn single quote!