Page 1 of 1 1
Topic Options
#159676 - 2006-03-23 03:46 PM problem with shell
eyal Offline
Lurker

Registered: 2006-03-23
Posts: 1
Hi
i am trying to insert data into mysql database using mysql client
for example :
$firstname=eyal
$lastname=sperling
shell 'mysql -u root test -e "insert into info(first,last) values ('$first','$last')"'

this mysql command is running fine from command line but not from shell ... i guess the problem is the quotes around the values . i tried several combination of single/double quotes but none of them works . any idea ?

Thanks
eyal

Top
#159677 - 2006-03-23 04:04 PM Re: problem with shell
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
Try this:
Code:
shell 'mysql -u root test -e "insert into info(first,last) values ('+"'"+$first+"','"+$last+"'"+')"'


Top
#159678 - 2006-03-23 04:11 PM Re: problem with shell
Richard H. Administrator Offline
Administrator
*****

Registered: 2000-01-24
Posts: 4946
Loc: Leatherhead, Surrey, UK
When things start to get tricky with quotes I often find it easier to create a couple of simple functions to do the work for me:
Code:
$sCommand='mysql -u root test -e '+DQuote('insert into info(first,last) values ('+SQuote($first)+','+SQuote($last)+')')

SHELL $sCommand

Function SQuote($s) $SQuote="'"+$s+"'" EndFunction
Function DQuote($s) $DQuote='"'+$s+'"' EndFunction


Top
#159679 - 2006-03-24 03:59 AM Re: problem with shell
Sealeopard Offline
KiX Master
*****

Registered: 2001-04-25
Posts: 11165
Loc: Boston, MA, USA
Or the DBCommand() UDF.
_________________________
There are two types of vessels, submarines and targets.

Top
Page 1 of 1 1


Moderator:  Jochen, Allen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Arend_, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 1376 anonymous users online.
Newest Members
batdk82, StuTheCoder, M_Moore, BeeEm, min_seow
17885 Registered Users

Generated in 0.055 seconds in which 0.027 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org