Jump to content

[SOLVED] Connecting to my database on localhost


joziv

Recommended Posts

I have installed PHP 5, Apache and MySQL on my machine, which runs on Windows Vista.

 

Apache tells me it's working (at http://localhost/), and the status bar in the Apache Service Monitor tells me it's connected to PHP/5.2.10.

 

However I seem to be having problems connecting to my database. I am using a simple php page to test the connection to the database, but it just returns a blank page, which has nothing in the source code. My test.php file is:

 

<?php

  $mysqli = new mysqli("localhost", "root", "password", "db");

 

  if (mysqli_connect_errno()) {

      printf("Connection failed: %s\n", mysqli_connect_error());

      exit();

      }

  else {

      printf("Host information: %s\n", mysqli_get_host_info($mysqli));

      mysqli_close($mysqli);

  }

?>

 

I can use MySQL on the database through a MySQL Line Client, so I'm not sure where the error is - I think it may be in the php.ini file? I have not altered it yet.

 

After many hours of googling the problem, and reinstalling everything, I'm getting a bit fed up. I have added the PHP directory to the windows path. Any help will be greatly appreciated!

 

Cheers.

Link to comment
Share on other sites

Hmm ok. Well I've now changed some error settings in php.ini and it produces this error:

 

Fatal error: Class 'mysqli' not found in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\test.php on line 2

 

I've been looking up this error and tried various things, but to no avail yet.

 

Anyone else seen this error before?

Link to comment
Share on other sites

it just returns a blank page
There are likely fatal runtime errors due to the mysqli php language extension not being enabled.

 

Edit: I'm guessing you did this -

You should be learning php, developing php code, and debugging php code on a system with error_reporting set to E_ALL and display_errors set to ON in your php.ini to get php to help you. You will save a lot of time. Stop and start your web server to get any change made to php.ini to take effect and verify any change using a phpinfo(); statement.

 

If you manually installed php from the .zip package, all you should need to do in uncomment the extension=php_mysqli.dll line in your php.ini and stop and start your web server.

 

If you did something like use the .msi installer package to install php, you will need to use the Windows control panel add/remove (they named it something else in Vista) to enable the mysqli extension (or remove what the .msi installer did and install php manually using the .zip package.)

 

Link to comment
Share on other sites

Thanks, I uncommented that earlier - sorry forgot to mention that! I did install php using the zip file.

 

If it's any help, I can't see any details about MySQLi in my phpinfo page? I've read you should be able to see some sql information there...?

Link to comment
Share on other sites

Ok so I've made a discovery. Maybe this will shed some light on the situation for someone?

 

Using the code below, it turns out I don't have the mysqli libraries.

 

if (!function_exists('mysqli_init') && !extension_loaded('mysqli')) {

    echo 'We don\'t have mysqli!!!';

} else {

    echo 'Phew we have it!';

}

 

Does this help anything?

Link to comment
Share on other sites

Someone already mentioned that -

There are likely fatal runtime errors due to the mysqli php language extension not being enabled.

 

As long as the php.ini that you are changing is the one that php is using and you have uncommented the php_mysqli.dll line in the php.ini and restarted your web server and the axuiliary .dll file libmysql.dll that is used by that extension is in a folder that is part of the Windows PATH statement, it should work. Have you checked the web server log file for any related errors?

Link to comment
Share on other sites

And it's working! It was of course a mis-type on my behalf.

 

In php.ini, it used to read:

; Directory in which the loadable extensions (modules) reside.

extension_dir = "\ext\"

 

However, after looking into the Apache log errors I discovered it was looking to "\\ext\\" - which obviously has too many slashes making the directory very wrong. Simply changing it and resetting the server sorted it all out.

; Directory in which the loadable extensions (modules) reside.

extension_dir = "ext"

 

Many thanks to PFMaBiSmAd for suggesting to look in the log files.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.