Connect with sql in template.

Started by trasek, September 25, 2013, 10:54:36 PM

trasek

Hello. I want to conenct with sql in template..
I try to:
            {php}
            NativeMySQL::connect();
             $q=mysql_query("SELECT * FROM hb_knowledgebase");
             while ($row = mysql_fetch_array($q)) {
                 echo $row["body"];
             }
            {/php}   


But nothing happen.. Can someone help with that?

trasek

Ok create smarty function and connect in smarty. Work perfect.

tallship

If connecting from another host make sure you open up port 3306 on your firewall and comment the following line in your /etc/rc.d/rc.mysqld (or equivalent file on your distro):


# To allow outside connections to the database comment out the next line.
# If you don't need incoming network connections, then leave the line
# uncommented to improve system security.
SKIP="--skip-networking"


Sometimes you have to do this even from localhost, depending on how your virtualhosts are setup.

Also, you should ditch MySQL and upgrade to MariaDB 5.6.x - the distro you're using has already done so, and you might as well too in order to avoid problems later.
Bradley D. Thornton - Manager Network Services, NorthTech Computer   TEL: +1.310.388.9469 (US) | +44.203.318.2755 (UK) | +61.390.088.072 (AU) | +41.43.508.05.10 (CH)
Registered Linux User #190795 - "Ask Bill why the string in [MS-DOS] function 9 is terminated by a dollar sign. Ask him, because he can't answer. Only I know that." - Dr. Gary Kildall.