php mysqli: configuring issues - php

I am currently running an Apache 2.4 server with PHP 5.5.1, and it is connected to Django via mod_wsgi (in case that matters). This is all running on Oracle Linux. In this set-up, I am trying to use mysqli and the method mysqli_connect. However, I am facing issues with my mysqli set-up. I have used the following website: MySQLi Setup. However, even after running ./configure --with-mysqli=/usr/bin/mysqlconfig and ./configure --with-mysqli, I still do not see a mysqli section in my phpinfo() test site. I have run make and make install after both and it has worked fine.
Furthermore, when I try the following command ./configure --with-mysql=/usr/bin/mysql_config --with-mysqli=mysqlnd, I get the following error: configure: error: Cannot find MySQL header files under /usr/bin/mysql_config. Note that the MySQL client library is not bundled anymore!
On top of this, I have uncommented the extension=php_mysqli.dll line.
Right now, I have an idea of what I need to do, which is to get ahold of the MySQL client library and allow access to it by php. However, I am unsure of how to do this, and many of the questions + answers I have found have not worked.
Any help is appreciated. Thanks.

Related

MySQLi with PHP 8.0.6: Unsupported anymore

i was updating my production server with php 8 and i discovered an error "Fatal Error: Class mysqli not found". So i asked to the support and they told me that "according to php official manual, mysqli is not supported anymore in php 8".
I tried to find any news on the internet about this, but i can't find anything.
Looking at the php changelog, they talk about bugfixes for mysqli library until PHP 8.0.2, then nothing.
Looking at the MySQLi official page on the php manual, there is only "PHP5, PHP7" as supported (while there is PHP 8 on PDO instead).
So, has somebody any news about this? What happened?
I got the same problem installing Wamp Server on a local machine with PHP 8.0.6, so i think they really removed MySQLi from the library, but in both local and production doing a phpinfo() i can clearly see "mysqli" extension installed.
Thank you in advance.
EDIT:
About the production server, basically, provider told me "use sp-php instead of php", and now mysqli works.
About the PHP.net, i think they forgot to add the support.
It's just a documentation problem. There's a pull request to add PHP/8 to the supported versions but it hasn't made its way to live yet.
mysqli is still supported with php ≥8.
In my Ubuntu (22.04) for example, it was not included in the distribution. You can install it at any time with:
sudo apt-get install php-mysqlnd
After rebooting php, everything works as expected.
Hope this helps

How to enable mysqli with PHP 7?

I have the latest version of Apache (Apache 2.4), latest version of PHP (PHP7), and latest version of MySQL (not sure the version but I have WorkBench version 6.3). In the past, when I checked if my PHP was working by this line of code <?php phpinfo(); ?> it would show that I have MySQL / mysqli installed and ready to go. But with PHP7 it shows mysqlnd.
I try using mysqli commands to check if I can connect to my database by mysqli_ping() and I also tried connecting to the database using server, user, pass. I keep getting errors such as Class mysqli not found. Or Call to undefined function mysqli_ping(). I've tried searching the net for some answers and All I could find was that I need to install MySQL (but a few sites said it was deprecated).
Am I able to get mysqli for PHP7? Or do I use mysqlnd? What is mysqlnd? Is it a new version of MySQL/mysqli?
Update 2020
For Windows 10 users I strongly recommend windows subsystem for linux (WSL 2) and setup your server there.
If you need php and mysql access in windows environment, then the fastest way is to install Wampserver. If you also need access to php through console then add php location (like C:\wamp64\bin\php\php7.4.11) to environment variables.
If that doesn't suit you and you need full setup always enabled on your system then follow install with choco.
To work properly with apache and load all needed extensions (including php_mysqli) you need ThreadSafe version of PHP, so make sure to download correct version or if you use Chocolatey to manage your windows applications, then just install php with this command:
choco install php --package-parameters='"/ThreadSafe "'.
This will install php in C:\tools\php72 directory, but you can overwrite it with another parameter:
choco install php --package-parameters='"/ThreadSafe ""/InstallDir:C:\PHP"""'.
The mysqlnd extension is part of PHP. It was developed as an alternative to bundling the libmysqlclient, because that library had license conditions that made it awkward to bundle with PHP.
You won't use mysqlnd directly. It's an internal library that is used by mysqli and pdo_mysql as a means to communicate with the MySQL Server.
As for mysqli, yes, it's available for PHP 7. I don't use Windows, but apparently not all extensions are enabled by default.
You probably need to edit your php.ini and uncomment the line
extension=ext_mysqli.dll
or whatever it is for that extension. It might already be in the file, but commented out. So go take a look and see.
Check if your system path environmental variable includes the PHP installation directory. That worked for me on with PHP 7.1 / Apache 2.4 / Windows Server 2016.

can't enable PDO in localhost apache php vesion 5.2.6

I can't enable PDO in my localhost.
I have read the php installation manual and attempted to do the same thing, but it isn't working.
When i open phpinfo and search for pdo it appear that pdo_mysql is not enabled, as shown in the below image.
I uncommented all pdo extension in php.ini and that didn't help.
I also searched for the pdo.dll in my extension and found it.
Any ideas what is wrong?
From the image of your phpinfo it's only showing sqllite and mysql is missing.
In PHP 5.2 I believe PDO is not available under default compile so you'll need to make sure it's actually compiled into PHP by adding --with-pdo-mysql into your compile script or if available via your webhosting panel somewhere. Personally I'd recommend having your PHP version updated to a secure version but as always you have to make sure any existing code is compatible.

CakePHP Class 'PDO' not found

I have shifted my CakePHP (2.3.1 stable version) site to Host-ed.me and I am getting PDO class not found error. How to enble PDO on Host-ed.me server. Any suggestion is highly appreciated.
I suggest to first compare your previous/local PHP configuration with the configuration on hosted.me.
You can do so by generating a phpinfo() report of both. be sure to remove the phpinfo page afterwards - having a publicly visible phpinfo page on your website is a major security risk.
Check if PDO is really not installed on the webserver, either via the phpinfo() report or via instructions found in this question; How to determine if PDO is enabled in PHP?
You may also check if hosted.me is not using an outdated version of php, otherwise you may run into other problems later on
If PDO is not installed and is required for your website (or the php version is too old), there's no other option than to contact the hosting provider and ask them if it is possible to have it installed or your website be hosted on a different server.
Finally, if these options do not give you a solution, find a better hosting provider that does have a decent PHP installation :)
Check out this blog for details.
Basically, you have to do the folllowing:
1. Check if PDO is installed (lookinto your phpinfo() output / write simple program)
2. Install PDO, using yum install php-pdo
Test again, using the above scripts and you should be good to go.
You just need to enable the PHP extensions:
pdo
pdo_sqlite
sqlite
or ask host to enable them

php odbc_connect to mssql works in linux/ubuntu command line not browser

I really feel like I have done an exhaustive search on this matter, found similar issues and have tried a number of things without success, so I am for the first time posting a question here:
I do a lot of web pages/web programming (PHP/jQuery mostly) and host these pages on my digital library department's Drupal/Ubuntu Server. I just code them and post them via Dreamweaver, as I don't have much use for the Drupal front end. I just need the server for my pages.
Anyway, I am wanting to make some PHP pages that can connect to our library catalog, so I have been working from the command line of the Drupal/Ubuntu server. I installed unixODBC, had some troubles, installed FreeTDS, set up the drivers and the DSN.
Finally...
I was able to get a connection to our catalog via tsql and run a query.
I made a basic PHP script to test the connection:
It works from the Ubuntu command line of the server (connection successful).
It doesn't work when I load it in a browser. I get the dreaded:
Warning: odbc_pconnect(): SQL error: [unixODBC][Driver Manager]Data source name not found, and no default driver specified, SQL state IM002 in SQLConnect in /var/www/mydirectory/mytestpage.php on line 15
UPDATE: I installed a test Ubuntu Server in a partition on my laptop, where I started clean, installed Apache2/PHP5(with mssql and odbc modules, etc)/FreeTDS, etc. I got a tsql connection. I made the basic PHP script and ran it successfully from the command line. Then I navigated to the php page from a browser and it worked! I still need to get this to happen on the Drupal server version, but now I have at least narrowed down the issue to something on the Drupal server.
I searched and found such possible causes as:
File permissions, which I think I got corrected, but no go
That maybe I had set up a User DNS and not a System DNS which I tried my best to correct with the proper "odbcinst" command options
That maybe php needs to be running in CGI mode instead of as a module. But that seemed unlikely from what I read. And I am not sure how that would affect Drupal. (There are limits to the system wide changes I should make here.)
A number of people said it was SElinux blocking Apache from displaying the page in the browser, but temporarily disabling SElinux didn't work.
Thanks for any assistance!
Check you have enabled the mssql.so etc at the following location
/etc/php5/apache2/php.ini, you will be having another at /etc/php5/cli/php.ini
in ubuntu php.ini will be maintained separately for cli & mod_php apache configuration
If you are going to test your odbc sources on the commandline, I would advise you use the isql utility instead of tsql. isql uses the DSN you defined in odbc.ini to connect to the database, while tsql connects directly to your database.
If it works with isql, it should work on your webpage as well.
Also check the Drupal/Ubuntu Server files /etc/odbc.ini (your DSN sources) and /etc/odbcinst.ini (TDS Driver settings) to see if they match the ones on the working Ubuntu installation.
My guess is it has something to do with the php. ini file. On my Ubuntu system I've got 2.
One in /etc/php5/apache2/php.ini
And one in /etc/php5/cgi/php.ini
The values in the apache2 path will need to be adjusted to allow the connection. Unfortunately outside of that I'm not too much use as I use MySQL and Mongo
Copy your php.ini from work server to non-work server, add make needed environment variables accessible before starting your web server, and make sure your web-server has full access to your odbc and odbcinst ini-files. And so, using mssql knowledge base or help.

Categories