Skip navigation
Currently Being Moderated

from RSS into multiple sql statements

Nov 16, 2007 9:54 PM

Hi all, I'm trying to import RSS into my database for this I created an XSLT
stylesheet that transforms the XML into a series of SQL statements like
below

INSERT INTO rss_feed(feed_title,feed_link,feed_description)
VALUES('',' http://...','');

SELECT @feed_id := MAX(feed_id) FROM rss_feed;

INSERT INTO
rss_channel(feed_id,channel_title,channel_link,channel_description,ch annel_language,channel_copyright,channel_managingeditor,channel_webmas ter,channel_pubdate,channel_lastbuilddate,channel_generator,channel_do cs,channel_cloud,channel_ttl,channel_image,channel_rating,channel_skip hours,channel_skipdays)
VALUES(@feed_id,'...','...','','','','','','','','','','','','','','', '');

SELECT @channel_id := MAX(channel_id) FROM rss_channel;

INSERT INTO
rss_item(channel_id,item_title,item_link,item_description,item_author ,item_comments,item_guid,item_pubdate)
VALUES(@channel_id,'...','','...','Joris van Lier','','','');

SELECT @item_id := MAX(item_id) FROM rss_item;

INSERT INTO
rss_enclosure(item_id,enclosure_url,enclosure_type,enclosure_length)
VALUES(@item_id,' http://...','...','...');


My problem is: I can pipe this into a command-line sql session but when
executing it from PHP it gives me a sql syntax error, running the statements
separately does not preserve the needed context with the foreign key
variables.

Second problem: how do I select the last inserted id in MySQL; is there an
equivalent to @@IDENTITY?

mysql Ver 14.7 Distrib 4.1.13, for unknown-linux-gnu (x86_64) using
readline 4.3

--
Joris van Lier

 
Replies
  • Currently Being Moderated
    Nov 16, 2007 11:33 PM   in reply to Newsgroup_User
    To get the ID of your inserted record you use the mysql_insert_id() function.

    $result = mysql_query($SQL);
    if(!$result)
    {
    echo $SQL . "<br /><br />";
    die("MySQL Error: " . mysql_error());
    }

    $FeedID= mysql_insert_id();

    As for the syntax errors I can't help you w/o seeing the full SQL statements.
     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)