Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

RSS from MySQL

Options
  • 08-11-2011 12:31pm
    #1
    Registered Users Posts: 459 ✭✭


    ...anyone have any idea why the script below isnt working please?

    It just shows the rss page title and description and nothing else - even if I intentionally place the wrong db details it does not throw an error...

    db_connect.php
    [PHP]<?php
    mysql_connect(`http://192.168.1.12`,`****`,`********`) or die(`Connect error`);
    mysql_select_db(`schema1`) or die(`Connect Error`);
    ?>[/PHP]

    index.php
    [PHP]<?php
    header("Content-type: text/xml");
    echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";

    echo "
    <rss version=\"2.0\"> ";

    echo "
    <channel>
    <title>Latest Listings</title>
    <description>Latest Job Listings</description>
    <link>http://***/</link>";

    require("db_connect.php");
    $data = mysql_query("SELECT * FROM project_master ORDER BY project_posted_date DESC LIMIT 10");
    while($row = mysql_fetch_array($data))
    {
    $row[project_title] = str_replace("images/", "http://***/images/",$row[project_title]);

    echo "
    <item>
    <link>http://***/project_".$row[project_id]."_".$row[project_title].".html</link&gt;
    <guid isPermaLink=\"true\">http://***/project_".$row[project_id]."_".$row[project_title].".html</guid&gt;
    <title>".$row[project_title]."</title>
    <description><!CDATA[".$row[project_description]."]]></description>
    </item>";
    }
    echo "
    </channel>
    </rss>";

    ?>[/PHP]


Comments

  • Registered Users Posts: 10,624 ✭✭✭✭28064212


    What if you do an echo "test" at the start of db_connect.php? Does that display?

    You're not getting error messages because you've used '@' in front of your SQL functions, it suppresses errors

    Boardsie Enhancement Suite - a browser extension to make using Boards on desktop a better experience (includes full-width display, keyboard shortcuts, dark mode, and more). Now available through your browser's extension store.

    Firefox: https://addons.mozilla.org/addon/boardsie-enhancement-suite/

    Chrome/Edge/Opera: https://chromewebstore.google.com/detail/boardsie-enhancement-suit/bbgnmnfagihoohjkofdnofcfmkpdmmce



  • Registered Users Posts: 459 ✭✭CSU


    ...removed @, changed db details and does not throw error.

    Echo "test" in db_connect.php does not show
    Echo "test" in index.php does not show:confused:


  • Registered Users Posts: 10,624 ✭✭✭✭28064212


    CSU wrote: »
    ...removed @, changed db details and does not throw error.

    Echo "test" in db_connect.php does not show
    Echo "test" in index.php does not show:confused:
    What happens if you take db_connect out of it (i.e. just put the connection code directly into index.php)?

    Boardsie Enhancement Suite - a browser extension to make using Boards on desktop a better experience (includes full-width display, keyboard shortcuts, dark mode, and more). Now available through your browser's extension store.

    Firefox: https://addons.mozilla.org/addon/boardsie-enhancement-suite/

    Chrome/Edge/Opera: https://chromewebstore.google.com/detail/boardsie-enhancement-suit/bbgnmnfagihoohjkofdnofcfmkpdmmce



  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    db_connect.php, line 3.

    mysql_select_db(`schema11) or die(1Connect Error`);

    You've got one big long string there.

    Basically you're asking it to select a database called "schema11) or die(1Connect Error"

    :)


  • Registered Users Posts: 459 ✭✭CSU


    [PHP]<?php
    mysql_connect(`http://192.168.1.12`,`***`,`***`) or die(`Connect error`);
    mysql_select_db(`schema1`) or die(`Connect Error`);

    header("Content-type: text/xml");
    echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";

    echo "
    <rss version=\"2.0\"> ";

    echo "
    <channel>
    <title>Latest Listings</title>
    <description>Latest Job Listings</description>
    <link>http://***/</link>";

    //require("db_connect.php");
    $data = mysql_query("SELECT * FROM project_master ORDER BY project_posted_date DESC LIMIT 10");
    while($row = mysql_fetch_array($data))
    {
    $row[project_title] = str_replace("images/", "http://***/images/",$row[project_title]);

    echo "
    <item>
    <link>http://***/project_".$row[project_id]."_".$row[project_title].".html</link&gt;
    <guid isPermaLink=\"true\">http://***/project_".$row[project_id]."_".$row[project_title].".html</guid&gt;
    <title>".$row[project_title]."</title>
    <description><!CDATA[".$row[project_description]."]]></description>
    </item>";
    }
    echo "
    </channel>
    </rss>";

    ?>[/PHP]

    Warning: mysql_connect() [function.mysql-connect]: [2002] No connection could be made because the target machine actively (trying to connect via tcp://localhost:3306) in E:\www\***\rss\index.php on line 2

    Warning: mysql_connect() [function.mysql-connect]: No connection could be made because the target machine actively refused it. in E:\www\***\rss\index.php on line 2

    E;
    192.168.1.12 (MySQL server) logs show no attempt of script connecting and or being refused...
    Is "(trying to connect via tcp://localhost:3306)" a fallback of somesort?


  • Advertisement
  • Registered Users Posts: 459 ✭✭CSU


    seamus wrote: »
    db_connect.php, line 3.

    mysql_select_db(`schema11) or die(1Connect Error`);

    You've got one big long string there.

    Basically you're asking it to select a database called "schema11) or die(1Connect Error"

    :)

    I saw that thanks - fixed, still not working...although I am unsure if I should be using " ' " or " ` " to define the MySQL parts


  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    CSU wrote: »
    I saw that thanks - fixed, still not working...although I am unsure if I should be using " ' " or " ` " to define the MySQL parts
    Actually that question should fix your problem. I assumed the above were single quotes that were just displaying wrong.

    Only use single-quotes or double-quotes to identify strings in PHP. ` is not a string identifier, this is why the script is attempting to connect to localhost as a fallback.


  • Registered Users Posts: 459 ✭✭CSU


    seamus wrote: »
    Actually that question should fix your problem. I assumed the above were single quotes that were just displaying wrong.

    Only use single-quotes or double-quotes to identify strings in PHP. ` is not a string identifier, this is why the script is attempting to connect to localhost as a fallback.

    [PHP]<?php
    mysql_connect('http://192.168.1.12','***','***') or die('Connect error1');
    mysql_select_db('schema1') or die('Connect Error2');

    header("Content-type: text/xml");
    echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";

    echo "
    <rss version=\"2.0\"> ";

    echo "
    <channel>
    <title>Latest Listings</title>
    <description>Latest Job Listings</description>
    <link>http://***/</link>";

    //require("db_connect.php");
    $data = mysql_query("SELECT * FROM project_master ORDER BY project_posted_date DESC LIMIT 10");
    while($row = mysql_fetch_array($data))
    {
    $row[project_title] = str_replace("images/", "http://***/images/",$row[project_title]);

    echo "
    <item>
    <link>http://***/project_".$row[project_id]."_".$row[project_title].".html</link&gt;
    <guid isPermaLink=\"true\">http://***/project_".$row[project_id]."_".$row[project_title].".html</guid&gt;
    <title>".$row[project_title]."</title>
    <description><!CDATA[".$row[project_description]."]]></description>
    </item>";
    }
    echo "
    </channel>
    </rss>";

    ?>[/PHP]

    I see - getting somewhere (I think)


    Warning: mysql_connect() [function.mysql-connect]: php_network_getaddresses: getaddrinfo failed: No such host is known. in E:\www\***\rss\index.php on line 2

    Warning: mysql_connect() [function.mysql-connect]: [2002] php_network_getaddresses: getaddrinfo failed: No such host is kn (trying to connect via tcp://http:3306) in E:\www\***\rss\index.php on line 2

    Warning: mysql_connect() [function.mysql-connect]: php_network_getaddresses: getaddrinfo failed: No such host is known. in E:\www\***\rss\index.php on line 2
    Connect error1


  • Registered Users Posts: 10,624 ✭✭✭✭28064212


    Based on this, remove "http://&quot; from the sql connection string

    Boardsie Enhancement Suite - a browser extension to make using Boards on desktop a better experience (includes full-width display, keyboard shortcuts, dark mode, and more). Now available through your browser's extension store.

    Firefox: https://addons.mozilla.org/addon/boardsie-enhancement-suite/

    Chrome/Edge/Opera: https://chromewebstore.google.com/detail/boardsie-enhancement-suit/bbgnmnfagihoohjkofdnofcfmkpdmmce



  • Registered Users Posts: 68,317 ✭✭✭✭seamus


    Jaysus, I'm not with it this morning, should have spotted that straight out.


  • Advertisement
  • Registered Users Posts: 459 ✭✭CSU


    Up and running :rolleyes:

    E;

    IE9, FF, Safari all work well but Chrome goes nuts???
    This XML file does not appear to have any style information associated with it. The document tree is shown below.

    ^^ any ideas??

    E2;
    nevermind...reading Google Chrome lacks an RSS reader by default so happy day's :)

    What are my options for securing db_connect.php ?

    I don't want anyone to be able to read it obviously...?


Advertisement