HTTP Request 500 when I call mysqli_connect with PHP - php

I want to use a database to store user data. I am running an Apache server with PHP and MySQL installed. When I try mysqli_connect, there is a HTTP 500 error. This is my code:
$con = mysqli_connect("localhost","root","password","database");
mysqli_close($con);
I also checked the Apache log; here's what it said:
[Time] [error] [client localhost] PHP Fatal error: Call to undefined function mysqli_connect() in [Document Address] on line 78, referer: [URL]
and
PHP Warning: PHP Startup: Unable to load dynamic library 'ext/php_mysqli.dll' - The specified module could not be found.\r\n in Unknown on line 0
Also, var_dump(function_exists('mysqli_connect')); outputs bool(false).
I've uncommented extension=php_mysqli.dll in php.ini, checked the ext directory and there is a php_mysqli.dll file in it, checked other StackOverflow (and other) questions like this, but none of this answered it for me.

test phpinfo () and make sure that the function is activated

Related

PHP SQLite Extensions not loading

I'm trying to load an extension on my PHP site:
$db->loadExtension('libdbplusql_81203.so');
PHP.ini:
sqlite3.extension_dir = /usr/lib/php/20180731
Error-Log from Apache2:
PHP Warning: SQLite3::loadExtension(): /usr/lib/php/20180731/libdbplusql_81203.so.so: cannot open shared object file: No such file or directory in /var/www/pdb/index.php on line 76
Can't figure out why this is not working.... and it's weird, that in the error log it says ".so.so" - when I change my code to:
$db->loadExtension('libdbplusql_81203');
Error Log say:
PHP Warning: SQLite3::loadExtension(): Unable to load extension at '/usr/lib/php/20180731/libdbplusql_81203' in /var/www/pdb/index.php on line 76
Maybe you have an idea :-)

Using WAMP to connect to SQL Server

I've read a lot of posts here on this problem, but I think mine is a little different because the output I'm getting doesn't match what others have had.
I am running WampServer Version 3.1.4 64bit and trying to connect to a SQL Server DB and I get the following error:
Fatal error: Uncaught Error: Call to undefined function sqlsrv_connect()
using the following code:
$serverName = "xxx.xxx.xxx.xxx";
$connectionInfo = array("Database" => "db_name", "UID"=>"sa", "PWD"=>"db_pwd");
$conn = sqlsrv_connect($serverName, $connectionInfo);
I have tried the following:
I downloaded the sql drivers for PHP 7 and 7.1 and tried them with the corresponding PHP versions
I made sure to restart all services after updating the php.ini file.
With my version of WAMP the php.ini file in the Apache folder is just a shortcut to phpForApache.ini in the php7.1.22 folder and it updates automatically.
The extensions DO show up in the WAMP menu: PHP > PHP extensions
and they have the green check mark next to them
I consistently get the following in my php_error.log:
[27-Nov-2018 14:25:16 UTC] PHP Warning: PHP Startup: Unable to load dynamic library 'c:/wamp64/bin/php/php7.1.22/ext/php_sqlsrv_71_nts.dll' - %1 is not a valid Win32 application.
in Unknown on line 0
[27-Nov-2018 14:25:16 UTC] PHP Warning: PHP Startup: Unable to load dynamic library 'c:/wamp64/bin/php/php7.1.22/ext/php_sqlsrv_71_ts.dll' - %1 is not a valid Win32 application.
in Unknown on line 0
As stated, I've tried using the appropriate dlls for both php 7 and 7.1.22 and got the same output:
[27-Nov-2018 15:12:37 UTC] PHP Warning: PHP Startup: Unable to load dynamic library 'c:/wamp64/bin/php/php7.0.32/ext/php_sqlsrv_7_ts_x86.dll' - %1 is not a valid Win32 application.
in Unknown on line 0
[27-Nov-2018 15:12:37 UTC] PHP Warning: PHP Startup: Unable to load dynamic library 'c:/wamp64/bin/php/php7.0.32/ext/php_sqlsrv_7_nts_x86.dll' - %1 is not a valid Win32 application.
I'm really not sure what other config I must be missing. I also tried the x64 versions, but I get an error stating the file could not be found, even though I triple checked the location.
Seeing as I get the same not a valid Win32 application error for both versions, I guess it's something outside of PHP

Changed PHP Version from 7.0.7 to 7.2.2 and back to 7.0 7 Now PHP is no longer working

I was testing an application to see if it would work in 7.0.7 and 7.2.2. The app works in both; that's not where the problem lies.
After seeing the app works in 7.2.2 I changed the Windows Apache httpd.conf file to:
LoadModule php7_module "C:/php_7_0_7/php7apache2_4.dll"
PHPIniDir "C:/php_7_0_7/"
from:
LoadModule php7_module "C:/php_7_2_2/php7apache2_4.dll"
PHPIniDir "C:/php_7_2_2/"
After changing the paths I restarted Apache.
Going to the URL localhost the webpage comes up correctly.
Going to localhost/phpinfo.php does not come up. The error message is "The site cannot be reached." The file phpinfo.php is simply <?php phpinfo(); ?>
The Apache error file has the following:
[Thu Feb 01 16:03:48.820715 2018] [core:warn] [pid 7628:tid 780] AH00098: pid file C:/Apache24/logs/httpd.pid overwritten -- Unclean shutdown of previous Apache run?
PHP Warning: PHP Startup: curl: Unable to initialize module\nModule compiled with module API=20151012\nPHP compiled with module API=20170718\nThese options need to match\n in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library 'php_fileinfo.dll' (tried: C:\php_7_0_7\ext\php_fileinfo.dll (The specified procedure could not be found.\r\n), C:\php_7_0_7\ext\php_php_fileinfo.dll.dll (The specified module could not be found.\r\n)) in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library 'php_gd2.dll' (tried: C:\php_7_0_7\ext\php_gd2.dll (The specified procedure could not be found.\r\n), C:\php_7_0_7\ext\php_php_gd2.dll.dll (The specified module could not be found.\r\n)) in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library 'php_intl.dll' (tried: C:\php_7_0_7\ext\php_intl.dll (The specified module could not be found.\r\n), C:\php_7_0_7\ext\php_php_intl.dll.dll (The specified module could not be found.\r\n)) in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library 'php_imap.dll' (tried: C:\php_7_0_7\ext\php_imap.dll (The specified procedure could not be found.\r\n), C:\php_7_0_7\ext\php_php_imap.dll.dll (The specified module could not be found.\r\n)) in Unknown on line 0
PHP Warning: PHP Startup: ldap: Unable to initialize module\nModule compiled with module API=20151012\nPHP compiled with module API=20170718\nThese options need to match\n in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library 'php_mbstring.dll' (tried: C:\php_7_0_7\ext\php_mbstring.dll (The specified procedure could not be found.\r\n), C:\php_7_0_7\ext\php_php_mbstring.dll.dll (The specified module could not be found.\r\n)) in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library 'php_exif.dll' (tried: C:\php_7_0_7\ext\php_exif.dll (The specified procedure could not be found.\r\n), C:\php_7_0_7\ext\php_php_exif.dll.dll (The specified module could not be found.\r\n)) in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library 'php_mysqli.dll' (tried: C:\php_7_0_7\ext\php_mysqli.dll (The specified procedure could not be found.\r\n), C:\php_7_0_7\ext\php_php_mysqli.dll.dll (The specified module could not be found.\r\n)) in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library 'php_openssl.dll' (tried: C:\php_7_0_7\ext\php_openssl.dll (The specified procedure could not be found.\r\n), C:\php_7_0_7\ext\php_php_openssl.dll.dll (The specified module could not be found.\r\n)) in Unknown on line 0
PHP Warning: PHP Startup: Unable to load dynamic library 'php_pdo_mysql.dll' (tried: C:\php_7_0_7\ext\php_pdo_mysql.dll (The specified procedure could not be found.\r\n), C:\php_7_0_7\ext\php_php_pdo_mysql.dll.dll (The specified module could not be found.\r\n)) in Unknown on line 0
PHP Warning: PHP Startup: pdo_sqlite: Unable to initialize module\nModule compiled with module API=20151012\nPHP compiled with module API=20170718\nThese options need to match\n in Unknown on line 0
PHP Warning: PHP Startup: xsl: Unable to initialize module\nModule compiled with module API=20151012\nPHP compiled with module API=20170718\nThese options need to match\n in Unknown on line 0
PHP Deprecated: Directive 'track_errors' is deprecated in Unknown on line 0
When I use the command line and run php -i "print phpinfo();" -> delete.txt is run everything looks OK. The windows environmental variable path includes "C:\php_7_0_7"
This is the line that I thought would indicate trouble with the extensions:
extension_dir => C:\php_7_0_7\ext => C:\php_7_0_7\ext
That is the correct path to the extensions.
PHP Error Reporting is set to E_ALL (this is a development machine)
display_errors = On
display_startup_errors = On
When a file that is just phpinfo(); the site can not be reached. Running a file that uses the mysqli extension to connect to a database comes up with this error "Fatal error: Uncaught Error: Call to undefined function mysqli_connect() in C:\www\mysqli.php:8 Stack trace: #0 {main} thrown in C:\www\mysqli.php on line 8"
When phpinfo is run from the command line and saved to a file it includes the lines:
mysqli
MysqlI Support => enabled
Which makes me think that php from the command line is working and there is some configuration or communication between Apache and PHP that I'm missing.
The service for IIS is turned OFF.
Edit 1: using the built in server started on the command line with php -S localhost:8000 everything works! However I would like to use Apache as that is what the main shop runs. Plus the port :8000 at the end of local host breaks the site.
Edit 2: When httpd.exe is stopped as a service and started by double clicking on it, everything runs just like it should. Perhaps this means there is a permission conflict between the service and the directories.
Update: works. does not work.
Is there an error log that is created when PHP starts?
How do I go about troubleshooting this? I'm on my 2nd hour and I'm seeking advice.
Thanks for all suggestions.
I had a very similar issue after upgrading my php, apache, and mysql stack. Specifically, everything seemed to work but none of the modules were available and I was sure the extension path was correct. When checking the error log I noticed similar entries to yours with file names like php_php_{module_name}.dll.dll.
During this process I copied an old php.ini file which listed module names like so:
extension=php_gd2.dll
;extension=php_gettext.dll
but when comparing to the php.ini-development or php.ini-production files, all modules are listed like:
extension=gd2
;extension=gettext
Just in case there were other changes that I missed, I ended up just copying the proper example file php.ini-development|php.ini-production and editing it to fit my environment again but you can probably get away with just removing the php_ and .dll segments from each of the extension listings.
Hope this helps someone else.
hi5, encountered the same exact problem today. Seems like lower Apache versions (I had 2.4.18) does properly load curl and openssl extensions. There's also an issue with new php.ini extension format (notice no "php_" and ".dll"), white readme states legacy format is still supported).
What solved my issue with two non-breaking steps:
Updated WAMP 3.0.2 to 3.1.1 using this
Updated Apache to 2.4.29 using this
Don't forget to switch Apache version in WAMP menu after restart and use new extension format in php.ini

PHP Startup: Unable to load dynamic library php_sqlsrv_54_ts.dll

I'm hopelessly stuck on this: I'm trying to connect to MS SQL Server 2008 R2 with PHP, but I can't seem to get the configuration right.
Windows Server 2012 Standard
MS SQL Server 2008 R2
PHP:
Version: 5.4.31
Branch: HEAD
Build: C:\php-sdk\php54dev\vc9\x86\obj\Release_TS
All I need is to call a PHP script from command line and save result to database. But I get following error:
C:\ankety>php uctenka.php 1012814411
PHP Warning: PHP Startup: Unable to load dynamic library 'C:\php-5.4.31-ts\ext\php_sqlsrv_54 in Unknown on line 0
Warning: PHP Startup: Unable to load dynamic library 'C:\php-5.4.31-ts\ext\php_sqlsrv_54_ts.dll in Unknown on line 0
PHP Fatal error: Call to undefined function sqlsrv_connect() in C:\ankety\zpracuj.php on line 157
Fatal error: Call to undefined function sqlsrv_connect() in C:\ankety\zpracuj.php on line 157
Now, of course there is correct version of php_sqlsrv_54_ts.dll in correct folder (C:\php-5.4.31-ts\ext\). In php.ini I changed:
extension_dir = "C:\php-5.4.31-ts\ext\"
extension=php_sqlsrv_54_ts.dll
When I run the script it also says that MSVCP100.dll is missing on a computer, but it is in fact there - in C:\Windows\System32 and I also tried C:\php-5.4.31-ts\ext\ but without luck.
In phpinfo() there isn't loaded sqlsrv part.
I don't know where I could possibly went wrong, I searched this problem but none of those solutions worked. Hope someone has an idea how to fix this.
For those, who don't want to waste time as myself - try restarting the IIS server :-)

Error in loading CodeIgniter site

My site was developed using CodeIgniter and was working fine before but now it's showing an error.
When I checked error log it's showing:
[07-Jul-2012 09:17:11] PHP Warning: PHP Startup: Suhosin Extension does not officially
support PHP 5.2 and below anymore, because it is discontinued. Use it at your own risk. in
Unknown on line 0
[07-Jul-2012 09:17:11] PHP Warning:
require(/home/maya3d/public_html/system/codeigniter/Common.php) [href='function.require'>function.require]: failed to open stream: No such file or directory in /home/maya3d/public_html/system/codeigniter/CodeIgniter.php on line 38 [07-Jul-2012 09:17:11] PHP Fatal error: require() [href='function.require'>function.require]: Failed opening required '/home/maya3d/public_html/system/codeigniter/Common.php' > (include_path='.:/usr/lib/php:/usr/local/lib/php') in /home/maya3d/public_html/system/codeigniter/CodeIgniter.php on line 38
Can anyone please help me to fix it?
Log into the server and run:
ls -l /home/maya3d/public_html/system/codeigniter/Common.php
If it says the file doesn't exist then there's your problem. It could be permissions related as well.

Categories