无法使用php显示数据库中的结果或选定元素

im new to php and trying to connect my db to php and test some queries but i can't get the result to print or show

$database = "kamel";

$c = mysql_connect($hostname) or die("Connecting to MySQL failed");

mysql_select_db($database);

$result = mysql_query("SELECT* FROM captain");

$r = mysql_fetch_assoc($result);

echo $r

?>

I see several Problems with your code:

  1. use var_dump($r); or print_r($r); to print an array (btw. u missed a ;)

  2. use PDO or mysqli to connect to a mysql database. "mysql_" was removed in PHP 7 and deprecated since 5.5 see: http://php.net/manual/de/mysqlinfo.api.choosing.php for more informations. The link gives you some simple examples too.

where remaing data base connection try the following connection

$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
   die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);