0

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.

informatik01
  • 16,038
  • 10
  • 74
  • 104
  • Honest question: why not use something already established, like XAMPP? – Mave Jan 14 '14 at 10:15
  • 1
    check your error_log (/var/log/apache2/error.log). – Flask Jan 14 '14 at 10:16
  • Well, you should get an error. Either the login credentials are wrong, or it should trigger an error when you try to run a query without a database selected (which you can't do if you're not logged into the server)... – BenM Jan 14 '14 at 10:16
  • 2
    @Mave Seriously? XAMPP on a LAMP-Stack? Are you kidding? – Flask Jan 14 '14 at 10:17
  • @BenM it has to be a Fatal error, if the credentials are wrong, the script would die and output the error – Flask Jan 14 '14 at 10:18
  • @Flask, what has to be a fatal error? – BenM Jan 14 '14 at 10:19
  • @BenM the error which occurs. either the table is empty and there is no error, or PHP throws a fatal which gets suppressed by config. (e.g. mysqli_connect isn't available). – Flask Jan 14 '14 at 10:21
  • 1
    Sounds like php is set to not display errors. You could turn them on in your php.ini `display_errors on` or in command line `tail -f /var/log/apache2/error.log` then watch it as you run your script in browser. This should show your error – adamS Jan 14 '14 at 10:23
  • 1
    No there is no any error even no any notice . Mave xamp on lamp :) – innovative kundan Jan 14 '14 at 10:25
  • It was an honest question - I don't know anything about Ubuntu. I've literally started using it 90 minutes ago. – Mave Jan 14 '14 at 10:26
  • You install `php5-mysql` but then try to use mysqli. – Álvaro González Jan 14 '14 at 10:26
  • 1
    related question? http://stackoverflow.com/questions/10769148/extension-mysqli-is-missing-phpmyadmin-doesnt-work – adamS Jan 14 '14 at 10:30
  • @Mave - It's the first time I hear that the official binaries of one of the leading Linux distros (specially crafted to fit into the system and receive automatic security updates) are not "established enough". What are the benefits of installing a third-party package? The fun of trying to make things work manually? – Álvaro González Jan 14 '14 at 10:31
  • have you restarted your webserver after installing php5-mysql? – Flask Jan 14 '14 at 10:34
  • 1
    Ok thats cool but in when i tries mysql instead of mysqli then is shows the same white screen – innovative kundan Jan 14 '14 at 10:34
  • Yes i have restarted my webserver and restart my pc too – innovative kundan Jan 14 '14 at 10:36
  • @ÁlvaroG.Vicario Never mentioned _anything_ about not being established enough? – Mave Jan 14 '14 at 11:13
  • @Mave - "why not use something already established" suggests so, doesn't it? In any case, the usual problem with official binaries is that they're normally very outdated (save for security patches). But they're fairly good for most situations since they "just work". – Álvaro González Jan 14 '14 at 11:19
  • Thanx all for suggestion now able to connect mysqli with php. It was silly mistake. – innovative kundan Jan 16 '14 at 10:46

1 Answers1

1

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.
Community
  • 1
  • 1
Álvaro González
  • 142,137
  • 41
  • 261
  • 360