mysql_select_db出错

时间:2015-06-19 20:51:16

标签: php mysql

我使用Linux Debian

本地灯服务器

我试图在Database和php之间建立连接:

<?php
$tf_host = 'localhost' ; 
$tf_dbname = 'tinyforum' ; 
$tf_username = 'root';
$tf_password = '' ;

$tf_handle = mysql_connect($tf_host , $tf_username , $tf_password);

if (!$tf_handle)
die('connection problem ..');
$tf_db_result = mysql_select_db($tf_dbname);
if($tf_db_result)
{
mysql_close($tf_handle);
die('selection problem');
}

die('OK');
mysql_close($tf_handle);
?>

结果:

http://www.foxpic.com/V0HrSdgb.png

phpmyadmin的照片:

http://www.foxpic.com/V0AlRhi6.png

我保存php文件的地方:

/无功/网络/ HTML /

1 个答案:

答案 0 :(得分:0)

除非您错误地复制了代码,否则您的检查不会产生您想要的结果。

$tf_db_result = mysql_select_db($tf_dbname);
if($tf_db_result)

您的选择似乎没问题,因此您应该将代码更改为

if(!$tf_db_result) //note the !

或重组您的代码

if($tf_db_result) {
     //Do the stuff you want to do when you are connected
} else {

 //Die connection
}
相关问题