Hi - The $valuesSeparatedByCommas worked fine, but I am still having problems executing a command on the database - After the loop that inserts the data into the databease, I'm using the following code to try to execute an sqlite commmand:
$sth = $dbHandle->prepare("select * from tab where i0=2"); $sth->execute(); and I get the following error: Fatal error: Call to a member function execute() on a non-object in /Library/WebServer/Documents/test3.php on line 41 After googling this error, I am worried that it is not a code problem. For example: http://www.dotproject.net/vbulletin/showthread.php?t=5667 I am running php 5.3.0 on Mac OS X 10.6.1 (Snow Leopard). Could it be a problem with my version of php? Frank Simon Slavin-3 wrote: > > > On 13 Dec 2009, at 5:27am, FrankLane wrote: > >> $data3 = preg_split('/\t/',$data2[$i]); // tab delimited record data >> into >> array >> >> $sqlcmd = 'INSERT INTO tab (i0) VALUES ('.$data3[0].')'; > > Good so far. Now you should know that a normal SQL command to insert a > record would look something like this: > > INSERT INTO tab(i0,i1,i2,i3,i4) VALUES (1,2,3,4,5) > > where the five values listed go into the five variables listed. So you > need to turn the array currently in $data3 into a list of variables. One > way to do it is this: > > $valuesSeparatedByCommas = preg_replace('/\t/', ',', $data2[$i]); > $sqlcmd = 'INSERT INTO tab(i0,i1,i2,i3,i4) VALUES > ('.$valuesSeparatedByComma.')'; > > another way to do it is this: > > $arrayOfValues = explode('/\t/',$data2[$i]); // tab delimited record data > into array > $valuesSeparatedByCommas = join(',', $arrayOfValues); > $sqlcmd = 'INSERT INTO tab(i0,i1,i2,i3,i4) VALUES > ('.$valuesSeparatedByComma.')'; > > > >> Looking in the php manual, there is no "query" function, but a lot of >> other >> xxx_query functions. Is this a simple problem" > > > I think you are best off using ->fetchAll for now. See > > http://php.net/manual/en/pdostatement.fetchall.php > > and scroll down to see some examples. This should allow you to prove that > the database system is working and give you confidence to try some of the > other functions. You will probably end up using either ->fetch() or > ->fetchObject(). > > (Warning: I haven't actually tried any of the above code.) > > Simon. > _______________________________________________ > sqlite-users mailing list > sqlite-users@sqlite.org > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users > > -- View this message in context: http://old.nabble.com/Sqlite-and-php-tp26754013p26764843.html Sent from the SQLite mailing list archive at Nabble.com. _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users