undefined function mysqli_connect() through url - php

I used to use Centos 7.2.1511, Apache 2.4.6, MariaDB5.5.52 and php 5.4 as my web server. But recently I updated php to 7.1.7. So I can't use functions like "mysql_connect()" anymore.
After I replaced them with "mysqli_connect()", I met a problem. I can execute the php file directly in the server successfully. But when I do it through the url, I get the error: Call to undefined function mysqli_connect().
Why did that happen? Is there something wrong with my Apache?

the command line version of php is not necessarily the same as the one used through apache.
(could still be on php 5.4)
But even if it was updated as well: you could have an other php.ini in both situation.
<?php phpinfo(); ?>
should reveal what php.ini is found and loaded

See if this helps: https://serverfault.com/questions/428800/how-do-i-tell-apache-which-php-to-use .
In my case the 'libphp5.so' file is located in
/etc/httpd/modules -> ../../usr/lib64/httpd/modules
You might have to copy the new files to this location or create symbolic links to the new files.

Related

PHP require_once called more than once

I posted the solution as an answer
I'm running into an odd issue while migrating some PHP code to a new server. The old server is running PHP 5.3 (x86) and the new server is running PHP 7.0 (x64). Both are running on IIS 7.5.
The code causing the issue has been in production without issues for almost three years. It runs fine on the current production server as well as two development systems. All three are running PHP 5.3 (x86).
These errors do not occur when I use PHP 5.3 (x86) on the new server.
A shared file (named _common_funcs.php) contains common functions that are called from many scripts. Since some of these scripts can interact I use require_once('_common_funcs.php') to include the file. This is approach pretty basic.
On the new server the first time a the script runs it generates a 'Cannot redeclare' error. Refreshing the page does not display the error - it displays the page as expected. For example:
//localhost/app/display_account.html?account=123456 generates the error.
//localhost/app/display_account.html?account=123456 again does not display the error.
Restarting the IIS server causes the error to be generated again on the first run.
Now for the odd part. Note the capitalization of the drive letters in the error below:
Cannot redeclare acct_has_graduated() (previously declared in D:\app_directory\includes\_common_funcs.php:2061) in d:\app_directory\includes\_common_funcs.php on line 2061
If I hardcode the full path in one require_once() line, and use a lowercase 'd', then the error in the log will swap the capitalization. This results is 'd:\app ...' and 'D:\app ...'.
If I hardcode both calls that happen to get called when this script runs with the error is not generated no matter what mix of capitalization I use.
And to make this just a little more interesting, the acct_has_graduated() function is the last function in the _common_funcs.php file. But if I disable OpCache in php.ini I get the following error:
Cannot redeclare update_ledger() (previously declared in D:\app_directory\includes\_common_funcs.php:7) in d:\app_directory\includes\_common_funcs.php on line 42
Two things of note: update_ledger() is the first function in the _common_funcs.php file, and "line 42" is the closing bracket of the update_ledger() function (line 7 is the declaration).
If anyone can point me in the right direction on this I would greatly appreciate it.
Solution
I found the issue and the file is absolutely being included twice. This happens under a specific set of circumstances. It affects PHP 7.0 but does not affect PHP 5.3. I did not test any other versions of PHP.
This scenario is certainly an outlier, but here it is:
I have a directory symlink from c:\inetpub\wwwroot\app_location to d:\app_location.
The IIS configuration for this site points to c:\inetpub\wwwroot\app_location.
The application's configuration file defines the include_path using c:\inetpub\wwwroot\app_location as the base.
All the files for this site are located in d:\app_location.
Using the configuration above all entries in the application's log files (tracking, audit, error and backtrace) show D:\app_location as the base location of all files.
Calling require_once() on a file more than once, while allowing the include_path to resolve the location of the file in one or both of the calls, generates the 'Cannot redeclare' error. The error reports the opposite capitalization of the 'D:' drive letter (see error text in the post above).
Changing the base of the include_path (#3 above) to d:\app_location resolved this issue.
The question is very simple.
require_once('D:\file.php');
require_once('file.php');
will run twice, because you included the absolute path!
Solution
Use relative path
require_once('../core/file.php');

Call to undefined function mb_detect_encoding() in Xampp after changing PHP version (PHPmyadmin)

I changed the default PHP version to an older one (5.3.28) but when I try to jump in to PHPMyadmin I get the error
*Fatal error: Call to undefined function mb_detect_encoding() in C:\xampp2\phpMyAdmin\libraries\php-gettext\gettext.inc on line 177*
Browsing trough this forum I found that this means I need the mbstring library
I enabled it in php.ini like this:
extension=php_mbstring.dll
But I keep receiving the same error.
I checked the extensions directory
extension_dir="C:\xampp2\php5328\ext"
and its correct, and the extension file is there as well (php_mbstring.dll)
But when I load phpinfo() I cant find any mention of mbstring.
Any ideas?
Got it solved #.# I was clicking config in XAMP and I thought it would for some reason open automatically the old php file (even tho Xampp is already configured to use the new one)
So yeah X) I was modifying the wrong php.ini
Thanks!

"The specified procedure could not be found" IIS 6.0 and PHP5

I am trying to make PHP5 work over IIS 6.0 on Windows server 2003 and i am following this steps:
http://www.iisadmin.co.uk/?p=4
The thing is, there's no file named "php5isapi.dll" inside the php folder, so I am using php5isapi.dll instead. Is it correct? Or should I try to download the php5isapi.dll from somewhere.
Well, then, I keep following the steps and when I try to execute my php file, I get this message:
The specified procedure could not be found.
What am I doing wrong?
Thanks.
UPDATE
I downloaded php5isapi.dll and tried to make it work with it but i am getting this error:
The specified module could not be found.
Also, after any change, i restart the Default Web Site clicking on stop and play.
UPDATE 2
Now, after rebooting, when trying to access the PHP file, the browser shows a 500 error:
The page cannot be displayed
I noticed that "php5isapi.ll" is no longer available for the last versions of PHP as pointed in here:
Why is php5isapi.dll missing after installing PHP for Windows?
Therefor, what i did was following this tutorial in order to do it with FastCGI
http://www.iis.net/learn/application-frameworks/install-and-configure-php-applications-on-iis/using-fastcgi-to-host-php-applications-on-iis-60
I found it on this comment:
Why is php5isapi.dll missing after installing PHP for Windows?
After restarting the server, it finally worked.

Fatal error: Call to undefined function mysql_connect() in C:\Apache\htdocs\test.php on line 2

Fatal error: Call to undefined function mysql_connect() in C:\Apache\htdocs\test.php on line 2
I've spent 11 hours today trying to get past this ONE problem.
I have installed:
MySQL 5.1
Apache 2.2.14
PHP 5.2.17
these were the versions referred to in the book "PHP and MySQL".
When I run the script:
<?php
mysql_connect ('localhost', 'root', 'password');
?>
where localhost, root and password are the REAL values for this given test
system and all I have seen is:
Fatal error: Call to undefined function mysql_connect() in C:\Apache\htdocs\test.php on line 2
Uncomment the line extension=php_mysql.dll in your "php.ini" file and restart Apache.
Additionally, "libmysql.dll" file must be available to Apache, i.e., it must be either in available in Windows systems PATH or in Apache working directory.
See more about installing MySQL extension in manual.
P.S. I would advise to consider MySQL extension as deprecated and to use MySQLi or even PDO for working with databases (I prefer PDO).
I had the similar issue. I solved it the following way after a number of attempts to follow the pieces of advice in the forums. I am reposting the solution because it could be helpful for others.
I am running Windows 7 (Apache 2.2 & PHP 5.2.17 & MySQL 5.0.51a), the syntax in the file "httpd.conf" (C:\Program Files (x86)\Apache Software Foundation\Apache2.2\conf\httpd.conf) was sensitive to slashes.
You can check if "php.ini" is read from the right directory. Just type in your browser "localhost/index.php". The code of index.php is the following:
<?php
echo phpinfo();
?>
There is the row (not far from the top) called "Loaded Configuration File". So, if there is nothing added, then the problem could be that your "php.ini" is not read, even you uncommented (extension=php_mysql.dll and extension=php_mysqli.dll). So, in order to make it work I did the following step. I needed to change from
PHPIniDir 'c:\PHP\'
to
PHPIniDir 'c:\PHP'
Pay the attention that the last slash disturbed everything!
Now the row "Loaded Configuration File" gets "C:\PHP\php.ini" after refreshing "localhost/index.php" (before I restarted Apache2.2) as well as mysql block is there. MySQL and PHP are working together!

PHP, MySQL on IIS - MySQL not being loaded when serving pages

I have, as best as I can manage, set up IIS (6.0), PHP (5.2.8) and MySQL (5.1.30) on Windows Server 2003, with all the involved mucking about (I think) in IIS and PHP to get things talking to each other.
PHP does work - however, I cannot use the mysql or mysqli libraries from a PHP page.
Fatal error: Class 'mysqli' not found in...
Fatal error: Call to undefined function mysql_connect() in...
Information relating to MySQL or MySQLi does not appear when using phpinfo() in a PHP page.
However, when I invoke PHP from the command line, such as
> php -r phpinfo()
Information relating to MySQL and MySQLi does appear in the output from that.
Restarting IIS or the OS does not produce further effect. I have only one php.ini file, in the PHP root directory.
Do I need to connect MySQL to IIS somehow as well, or is there another problem?
The php.ini file used for command-line usage of PHP may be different from the php.ini used by the web server. You should get phpinfo() information by putting a small PHP script under your web server's document space:
<?php
phpinfo();
?>
Open this PHP script by using your browser to request that PHP script via an URL to your web server. That will tell you what the web server thinks is your PHP configuration.
Also remember that you need to restart the web server for edits to php.ini to take effect. It only reads the php.ini when the web server starts.
There are numerous places the php.ini file that your IIS instance is using might live. See http://php.net/manual/en/configuration.php or http://www.iis-aid.com/articles/how_to_guides/where_php_ini_is_loaded_from for details.
Look at the output of phpinfo() when viewed in your browser, and look for the item "Loaded Configuration File".

Categories