tenacious-dee Posted February 19, 2009 Share Posted February 19, 2009 Hi guys Im having difficulty getting a php db connection script to work on my server which runs php safe mode.. Any ideas? This is the connection code.. <?php $mysql = mysql_connect("localhost","anmluser","8uhb2wsx","anmldb"); if(!$mysql){ printf("Connect failed: %s\n", mysql_error()); exit(); }else{ $sql = "SELECT news_name, news_date, news_location, news_desc from tblnews order by news_id desc limit 5"; $res = mysql_query($mysql, $sql); if($res){ while($newArray = mysql_fetch_array($res, MYSQL_ASSOC)){ $title=$newArray['news_name']; $date=$newArray['news_date']; $location=$newArray['news_location']; $desc=$newArray['news_desc']; echo "<table cellpadding='4' style='border-bottom-style: dotted; border-color:purple;'>"; echo "<tr>"; echo "<td><font color='green' size='3pt'><b>".$title."</b></font></td>"; echo "<td><b><i>Posted:</b> ".$date."</i></td>"; echo "</tr>"; echo "<tr>"; echo "<td colspan=2><b>Location:</b> ".$location."</td>"; echo "</tr>"; echo "<tr>"; echo "<td colspan=2>".$desc."</td>"; echo "</tr>"; echo "</table>"; echo "<br/>"; } }else{ printf("Could not retrieve records: %s\n", mysql_error($mysql)); } mysql_free_result($res); mysql_close($mysql); } ?> this has been driving me mental so any advice is greatly appreciated! Thanks is advance! Link to comment https://forums.phpfreaks.com/topic/145905-php-safe-mode-database-connection/ Share on other sites More sharing options...
runnerjp Posted February 19, 2009 Share Posted February 19, 2009 have you got this sorted yet? Link to comment https://forums.phpfreaks.com/topic/145905-php-safe-mode-database-connection/#findComment-766224 Share on other sites More sharing options...
PFMaBiSmAd Posted February 19, 2009 Share Posted February 19, 2009 It would really help if you posted the error you are getting, but let me use a little mind reading to find out what you saw in front of you - "no database selected" The 4th parameter of mysql_connect() is NOT the database, it is a flag that determines if a new connection should be made. When your mysql_query() executed, there is no database connection. You need to have a mysql_select_db() statement in your code. Link to comment https://forums.phpfreaks.com/topic/145905-php-safe-mode-database-connection/#findComment-766578 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.