0

I keep getting this error:

Fatal error: Uncaught Error: Call to undefined function mysqli_connect() in C:\Apache24\htdocs\asd.php:2 Stack trace: #0 {main} thrown in C:\Apache24\htdocs\asd.php on line 2

when simply running any mysqli cmd in any php file e.g :

<?php  $con = mysqli_connect('localhost','my_user','my_password','my_db'); ?>

I have already enabled the extension in my php.ini file and I've been trying to figure this out for a while and I just can't. Any help would be greatly appreciated.

Barmar
  • 741,623
  • 53
  • 500
  • 612
sinsy
  • 1
  • 1
    You must not have enabled the extension correctly. – Barmar Dec 31 '19 at 00:52
  • Did you restart apache after enabling it? – Barmar Dec 31 '19 at 00:53
  • well i enabled uncommented "extension=mysqli" and have and yes i have restarted apache thanks for the help, i have been trying to fix this for hours with no success – sinsy Dec 31 '19 at 01:02
  • Make sure you updated the correct php.ini. There are separate init files for CLI and web. – Barmar Dec 31 '19 at 01:13
  • are they both in the same php directory ? if not i have edited the only on in my php dir – sinsy Dec 31 '19 at 01:21
  • im sorry, im new to php and mysql , i don't know where those seperate files are contained – sinsy Dec 31 '19 at 01:22
  • 2
    [How to find location of php.ini](https://www.ostraining.com/blog/coding/phpini-file/) – Barmar Dec 31 '19 at 01:24
  • then yes I have the right php.ini – sinsy Dec 31 '19 at 08:57
  • According to [this question](https://stackoverflow.com/questions/25281467/fatal-error-call-to-undefined-function-mysqli-connect) the line in php.ini should be `extension=php_mysqli.dll` – Barmar Dec 31 '19 at 19:37
  • but see that is the problem, my file doesn't contain `extension=php_mysqli.dll` so i tried adding it and resetting apache and it still does not work.There is actually no .dll in my php.ini – sinsy Dec 31 '19 at 19:42
  • Maybe you don't have the extension in the first place and need to download it. – Barmar Dec 31 '19 at 19:44
  • when i run this cmd it shows that i have sql right ?`C:\php>php.exe -m [PHP Modules] bcmath calendar Core ctype date dom filter hash iconv json libxml mysqli mysqlnd pcre PDO pdo_mysql pdo_sqlite Phar readline Reflection session SimpleXML SPL standard tokenizer xml xmlreader xmlwriter zip zlib [Zend Modules]` – sinsy Dec 31 '19 at 19:46
  • 1
    Don't know what to tell you. Does the extension show up in `phpinfo()` on the web? – Barmar Dec 31 '19 at 19:50
  • the question you have referenced does not solve my problem by the way, i don't know why this is so complicated and yes it does show up – sinsy Dec 31 '19 at 19:51
  • 1
    @sinsy Please [edit] your question to include a screenshot of the "mysqli" section of the page generated by `phpinfo();`. – Progman Dec 31 '19 at 19:58

1 Answers1

-3

Can you try this code below:

    $con=mysqli_connect("localhost","my_user","my_password","my_db");

if (mysqli_connect_errno()) {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  exit();
}

And let me if it works thanks.

R.Shamon
  • 65
  • 1
  • 8
  • this is what I get when I execute it `Fatal error: Uncaught Error: Call to undefined function mysqli_connect() in C:\Apache24\htdocs\asd.php:2 Stack trace: #0 {main} thrown in C:\Apache24\htdocs\asd.php on line 2` – sinsy Dec 31 '19 at 09:00
  • it seems as if php doesn't even recognize what mysqli_connect() is and stops execution right there , but I have all the prerequisites needed. – sinsy Dec 31 '19 at 09:01
  • What's the point of this answer? If the function doesn't exist, how can it set the error code? – Barmar Dec 31 '19 at 19:35
  • Please read: [Should we ever check for mysqli_connect() errors manually?](https://stackoverflow.com/q/58808332/1839439) – Dharman Dec 31 '19 at 23:45
  • I think the best way is to speak to your hosting provider and tell them what the issue is, by the way I don’t know why did I get minus 3, the code I provide it earlier was just in case that @sinsy was not typed in correctly, please fix thanks – R.Shamon Jan 01 '20 at 04:24