简体   繁体   English

在Ubuntu 13.10上将PHP与MySQL连接

[英]Connect PHP with MySQL on Ubuntu 13.10

I have installed Ubuntu 13.10 and also installed MySQL and PHP. 我已经安装了Ubuntu 13.10,还安装了MySQL和PHP。 When running separately, both PP and MySQL are working fine. 当分别运行时,PP和MySQL都可以正常工作。 However when I try to connect MySQL with PHP, it does not show any errors nor will it connect. 但是,当我尝试将MySQL与PHP连接时,它不会显示任何错误,也不会连接。 Separately PHP and MySQL are working fine. 另外,PHP和MySQL运行正常。 I also run this command: 我也运行以下命令:

sudo apt-get install php5-mysql 

It shows every thing updated and that I have installed PHP and MySQL. 它显示了所有更新的内容,并且我已经安装了PHP和MySQL。

I used: 我用了:

mysqli_connect('localhost','root','root') or die(mysqli_error());

mysqli_select_db('databasename') or die(mysqli_error());
$resources = mysqli_query('select * from users');
while ($data=mysqli_fetch_object($resources)) {
   echo "<pre>";
   print_r($data);
}

but the pages show a white screen. 但页面显示白屏。

Here you are a couple of hints: 这里有一些提示:

  • A blank page (or a "500 Internal Server Error" status code) means that your script is throwing an error but you haven't configured PHP to display error messages. 空白页(或状态代码为“ 500 Internal Server Error”)表示您的脚本抛出错误,但您尚未配置PHP以显示错误消息。 That's something you need to fix before you go further; 这是您需要进一步解决的问题。 it's impossible to code properly without the aid of error messages. 没有错误消息的帮助,就不可能正确编码。 Here's a brief explanation . 这是一个简短的解释

  • You've apparently installed the deprecated legacy mysql extension ( Original MySQL API ): 您显然已经安装了已弃用的旧版mysql扩展( Original MySQL API ):

     apt-get install php5-mysql 

    ... but you're actually using the modern mysqli extension ( MySQL Improved Extension ); ...但是您实际上正在使用现代的mysqli扩展( MySQL改进的扩展 ); note the trailing i . 注意尾随

To sum up: 总结一下:

  • Make sure you're able to see error messages (there's no need to guess). 确保您能够看到错误消息(无需猜测)。
  • Browse for the correct package. 浏览正确的软件包。

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

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