Jump to content

php safe mode database connection


tenacious-dee

Recommended Posts

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

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.