donglefu6195 2015-06-19 20:51
浏览 51
已采纳

mysql_select_db错误[关闭]

I use Linux Debian

Local Lamp Server

i tried to make connection between Database and 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);
?>

The result :

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

pic of phpmyadmin:

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

the place where i save the php file :

/var/www/html/

  • 写回答

1条回答 默认 最新

  • dongzi3805 2015-06-19 21:10
    关注

    Unless you copied your code incorrectly, your check is not going to result in what you want.

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

    your selection seems fine so either you should change your code to

    if(!$tf_db_result) //note the !
    

    or restructure your code

    if($tf_db_result) {
         //Do the stuff you want to do when you are connected
    } else {
    
     //Die connection
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入