简体   繁体   中英

Connect PHP with MySQL on Ubuntu 13.10

I have installed Ubuntu 13.10 and also installed MySQL and PHP. When running separately, both PP and MySQL are working fine. However when I try to connect MySQL with PHP, it does not show any errors nor will it connect. Separately PHP and MySQL are working fine. I also run this command:

sudo apt-get install php5-mysql 

It shows every thing updated and that I have installed PHP and 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. 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 ):

     apt-get install php5-mysql 

    ... but you're actually using the modern mysqli extension ( MySQL Improved Extension ); 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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