简体   繁体   English

在PHP MySQL上未选择数据库

[英]No database selected on PHP MySQL

Error: No Database Selected 错误:未选择数据库

I have a website that was hosted with ARVIXE (windows 2008 server) and presently with IXWEBHOSTING (windows 2003 server). 我有一个托管有ARVIXE(Windows 2008服务器)和目前带有IXWEBHOSTING(Windows 2003服务器)的网站。 It was very simple to move. 移动非常简单。 It was a matter to just download/upload the site PHP files and export/import MySQL database and change the config PHP file to point to the new database information and voila! 只需下载/上传站点PHP文件并导出/导入MySQL数据库,然后更改配置PHP文件以指向新的数据库信息,瞧瞧!

Now I am trying to move the site to my own server. 现在,我试图将站点移到我自己的服务器上。 Trust me I have no problems with DNS, servers, networking stuff. 相信我,我在DNS,服务器和网络方面没有任何问题。 I've being doing this for 15 years (not programming). 我已经做了15年(不编程)。
This is my actual server: Windows 2003 STD SP2, IIS6, PHP5.2.12, MySQL 5.0.96, FastCGI 1.5. 这是我的实际服务器:Windows 2003 STD SP2,IIS6,PHP5.2.12,MySQL 5.0.96,FastCGI 1.5。 and all MS Updates. 和所有MS更新。

Now here me out before you conclude that is the code or MySQL permissions... I have read I think all the No Database Selected errors on the Internet including here and is usually a little code modification or missing code or permission issue on the database...but not this one, see the scenarios below and you will see why not. 现在,在得出结论之前,这里是我的代码或MySQL权限...我读过我认为,包括Internet在内的所有Internet上所有No Database Selected错误都包括在内,通常是一些代码修改或数据库上缺少代码或权限问题。 ..但不是这一类,请参阅下面的方案,您将明白为什么不这样做。

  • Scenario 1 PHP Files are sitting in the IXWEBHOSTING servers. 方案1 PHP文件位于IXWEBHOSTING服务器中。 The config PHP file points to my own MySQL server it works fine. 配置PHP文件指向我自己的MySQL服务器,它工作正常。

  • Scenario 2 PHP Files are sitting in the IXWEBHOSTING servers. 方案2 PHP文件位于IXWEBHOSTING服务器中。 The config PHP file points to IXWEBHOSTING MySQL server it works fine. 配置PHP文件指向IXWEBHOSTING MySQL服务器,它工作正常。

  • Scenario 3 PHP Files are sitting in my Win2k3 servers. 方案3 PHP文件位于我的Win2k3服务器中。 The config PHP file points to IXWEBHOSTING MySQL server, I get error "No database selected". 配置PHP文件指向IXWEBHOSTING MySQL服务器,出现错误“未选择数据库”。

  • scenario 4 PHP Files are sitting in my Win2k3 servers. 方案4 PHP文件位于我的Win2k3服务器中。 The config PHP file points to my own MySQL server, I get error "No database selected". 配置PHP文件指向我自己的MySQL服务器,出现错误“未选择数据库”。

So I know for a fact it has nothing to do with MySQL permission on my own MySQL server or PHO code as scenario 1 proves it. 因此,我知道一个事实,这与场景1证明的有关我自己的MySQL服务器或PHO代码上的MySQL权限无关。 It seems to be a problem with PHP on my server. 我的服务器上的PHP似乎有问题。

Prior of installing the OLD PHP and MySQ, I had the lastest version of each PHP 5.3.13 and MySQL 5.5.25 and same FastCGI version. 在安装OLD PHP和MySQ之前,我拥有每个PHP 5.3.13和MySQL 5.5.25的最新版本以及相同的FastCGI版本。 I had the exact same problem!!!! 我有同样的问题!!!! The reason why I installed the old versions is because I wanted to match IXWEBHOSTING server versions. 我安装旧版本的原因是因为我想匹配IXWEBHOSTING服务器版本。

Prior to the above installations, Windows was installed from scratch each time on a hyper-v server. 在进行上述安装之前,每次都在Hyper-v服务器上从头开始安装Windows。 No updates MS updates were done on the server the first attemps and the last installation it has all the MS updates and I still have the same problem. 没有更新MS更新是在第一次尝试和最后一次安装时在服务器上完成的,它具有所有MS更新,但我仍然遇到相同的问题。

I had the same problem with Windows 2008 STD, PHP 5.3.13 and MySQL 5.5.25. 我在Windows 2008 STD,PHP 5.3.13和MySQL 5.5.25中遇到了相同的问题。

PHP is loading all the proper extensions to make the connections to MySQL. PHP正在加载所有适当的扩展以建立与MySQL的连接。 I also have PHPmyAdmin running without problems. 我也有PHPmyAdmin运行没有问题。

I also tried with in the config file and no luck 我也在配置文件中尝试过,没有运气

There is a lot of stuff in the index but this is what is needed to make the connection to the database and the query and where it fails. 索引中有很多东西,但这是建立与数据库和查询的连接以及失败的地方。

config file 配置文件

<?
$usuarios_sesion="youth";
$host="localhost";
$user="usernamehere";
$pass="passwordhere";        
$db="databasehere";
$tabla="users";
?>

Index.php File Index.php文件

<?
require ("enlaces_config.inc.php");

$menu=mysql_query("SELECT id_cat, name_cat FROM categories WHERE access=0 AND published=1") or die ("Can't select categorias MySQL says: ".mysql_error());

?>

At this point I have no idea what else it can be... permissions, maybe but not in MySQL permission, the user has full priviledges to the database. 在这一点上,我不知道还有什么...权限,也许但在MySQL权限中却不是,用户拥有对数据库的完全特权。 Scenario 1 and 2 proves it too. 场景1和2也证明了这一点。

If you need to check PHP information let me know. 如果您需要查看PHP信息,请告诉我。 I will post the name of the php file for excution 我将发布php文件的名称以供执行

Help! 救命!

The problem is not with all that you have written wrt your server. 问题不在于服务器编写的所有内容。
When you try to fetch data from a database you must essentially follow these steps- 当您尝试从数据库中获取数据时,您必须执行以下步骤:

  1. Create a connection 建立连接

    That involves connecting using Database, User Name, and Password, along with Hostname. 这涉及使用数据库,用户名和密码以及主机名进行连接。 You can use mysql_connect() , although deprecated . 您可以使用mysql_connect() ,尽管已弃用

  2. You need to select the database from that host. 您需要从该主机中选择数据库。

  3. You go for any mysql query using selected db connection in step 2. 您可以在步骤2中使用选定的数据库连接进行任何mysql查询。

I would suggest you to get a good grip on database concepts first and then implementation using php. 我建议您先掌握数据库概念,然后再使用php实施。
Best place to start http://w3schools.com 最佳起点http://w3schools.com

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM