0

So I'm trying to work with databases in php. It did not recognize the function mysqli_connect() and after I looked up on google for a bit, I realised that I need to modify something in the php.ini file.

However, I do not have such a file. I opened in browser this code: <?php phpinfo(); ?> but I have no path for that file, as you can see here. What can I do now?

anon
  • 1
  • 1
  • Then you'll probably need to add a file yourself in the location expected by your PHP distribution. What's your operating system and were did you get PHP from? – Álvaro González Apr 16 '22 at 17:35
  • But I don't really know what location is expected. I use Windows and I got php from php.net @ÁlvaroGonzález – anon Apr 16 '22 at 17:37
  • 1
    Then the file must be in the folder where you unzipped PHP. I recommend you create it by copying one of the templates you'll find (choose `php.ini-development` if you're going to develop PHP code in this machine). – Álvaro González Apr 16 '22 at 17:38
  • Assuming you installed one of the [windows.php.net builds](https://windows.php.net/download/), you _should_ have a `php.ini` in your PHP installation directory root. My dev laptop runs Windows and phpinfo says: `Configuration File (php.ini) Path no value Loaded Configuration File C:\server\php\php.ini `. – Markus AO Apr 16 '22 at 17:42
  • To be exact, you will have `php.ini-development` and `php.ini-production` there. (Just updated to 8.1.5 and looked up what's in the zip file.) Rename one of them, probably the `php.ini-development`, to `php.ini` only. – Markus AO Apr 16 '22 at 17:52
  • @ÁlvaroGonzález Thanks! Now I do have a file path where it says "Loaded Configuration File", but myqli_connect() still doesn't work and I don't have permission to modify it.. – anon Apr 16 '22 at 17:54
  • @MarkusAO yep, I copied the php-development and renamed it, and now I have a path for "Loaded Configuration File", but I can't modify the new php.ini so that I can use the mysqli extension. – anon Apr 16 '22 at 17:56
  • Why can't you modify it? Just modify it. :) And then restart Apache. – Markus AO Apr 16 '22 at 18:02
  • @MarkusAO lol it says I do not have permission :') And that the administrator/owner of the file should modify it. – anon Apr 16 '22 at 18:06
  • You don't have permissions to edit a file you have just created? Have you installed PHP into a system folder? In any case, that's something you'll need to discuss with your systems administrator. And, if you are the system's administrator, just right click on the file, select "Properties" and take ownership of the file. – Álvaro González Apr 16 '22 at 18:08
  • You probably want to have your PHP not in Program Files or other system folders, that's just a headache, with absolutely no benefits. Just toss it into `c:/server/php` or something. – Markus AO Apr 16 '22 at 18:12
  • @ÁlvaroGonzález oops didn't know I can just do that lol, thanks, it worked. – anon Apr 16 '22 at 18:23
  • @MarkusAO yeah when I installed it I saw that I should install it in Program Files or smth so I put it there. I changed permissions and I could modify. The mysqli function still doesn't work but oh well :') – anon Apr 16 '22 at 18:24
  • It's easy enough to move out from there if necessary. If you have uncommented `;extension=mysqli` in your `php.ini` and restarted Apache, there's no reason the function shouldn't exist. Do you see mysqli in your phpinfo? – Markus AO Apr 16 '22 at 18:29
  • @MarkusAO NVM IT WORKED OMG I was about to turn off my pc and go to sleep lol. I also had to uncomment the 'extension_dir="ext" ' and replace "ext" with its full path. – anon Apr 16 '22 at 18:36
  • Right there are a couple of things you may need to customize to your setup. I see that I have also added the full path to my php.ini. For some reason the default fails to find any extensions, though you'd expect it to work? Check anything with `_path`, `_dir` and `_log` really, e.g. `include_path`, `error_log`, `sys_temp_dir`, `upload_tmp_dir`, `session.save_path`. – Markus AO Apr 16 '22 at 18:42
  • `extension_dir="ext"` should work fine, you don't need to provide a full path. But, for whatever the reason, it isn't the default. – Álvaro González Apr 17 '22 at 07:53

0 Answers0