PHP7 and pdo_mysql [duplicate] - mysql

This question already has answers here:
PDO drivers no value in Windows
(18 answers)
Closed 5 years ago.
I've just upgraded PHP5.6 to PHP7 on my XAMPP on Windows 10 following this guide. It works just fine, except for PDO.
In my phpinfo() I get PDO support enabled, PDO drivers no value.
I copied the php.ini-development and renamed it to php.ini, and I have uncommented the extension folder declaration, and the extention driver php_pdo_mysql.dll.
extension_dir = "ext"
...
extension=php_pdo_mysql.dll
I have verified that php_pdo_mysql.dll is located in C:\xampp\php\ext and when I run php -m in a console, both PDO and pdo_mysql are listed as active modules.
C:\xampp\php>php -m
[PHP Modules]
bcmath
calendar
Core
ctype
curl
date
dom
exif
filter
gd
gettext
hash
iconv
json
libxml
mbstring
mcrypt
mysqlnd
openssl
pcre
PDO
pdo_mysql
Phar
Reflection
session
SimpleXML
SPL
standard
tokenizer
wddx
xml
xmlreader
xmlwriter
zip
zlib
[Zend Modules]
When I run a script that utilizes PDO, I get thrown
Fatal error: Uncaught PDOException: could not find driver in (path to script)
The script I am running is completely valid and worked fine before the upgrade (basically just a new PDO(params)).
What am I missing?

For some reason, not sure why, Windows needs an absolute path to the extension dir. So instead of
extension_dir = "ext"
in php.ini, I put
extension_dir = "C:/xampp/php/ext"
and then restarted apache. Everything works again.
Maybe someone can elaborate on this issue?

Related

Qt Library 'mysql' is not defined

I have a problem with Qt connecting with MySql, when i run this code
QSqlDatabase DBObject = QSqlDatabase::addDatabase("QMYSQL");
DBObject.setHostName("localhost");
DBObject.setDatabaseName("SingleDB");
DBObject.setUserName("root");
DBObject.setPassword("abc123");
bool ok = DBObject.open();
and I got this... QSqlDatabase: QMYSQL driver not loaded
I Have already done this also:
sudo apt-get install libmysqlclient
and
/home/wrm/Qt/5.12.3/gcc_64/bin/qmake "INCLUDEPATH+=/usr/local/include" "LIBS+=-L/usr/local/lib -lmysqlclient_r" mysql.pro
and here i have this error: Project ERROR: Library 'mysql' is not defined
Any idea?
Perhaps you need to install mysql-devel.
According to the Qt Docs QMYSQL for MySQL 4 and higher:
How to Build the QMYSQL Plugin on Unix and macOS
You need the MySQL header files, as well as the shared library libmysqlclient.so. Depending on your Linux distribution, you may need to install a package which is usually called "mysql-devel".
Google doesn't have a readily available answer, so answering this old question:
Aside from needing development files as pointed above (like apt install libmysqlclient-dev), you need to generate a config:
# Just for making my snippet work. Feel free to hardcode paths.
export QTDIR=/home/you/Qt/
export QTVERSION=5.9.5
cd $QTDIR/$QTVERSION/Src/qtbase/src/plugins/sqldrivers
$QTDIR/$QTVERSION/gcc_64/bin/qmake sqldrivers.pro
cd mysql
make
make install # if you want; it installs it in the bin dir of $QTVERSION
In the past, this was not necessary for Qt 5.5 (where I did this last time).
On a side note, there is no longer a special thread-safe version of libmysqlclient (libmysqlclient_r). It's just one one. Last time I ran into that link error, I just edited the generate Makefile to use the non-_r.

How do I enable the intl extension in CakePHP?

I am using CakePHP 3 and MAMP Pro server for my project. When I am trying to bake the cake, this error shows up:
Fatal error: You must enable the intl extension to use CakePHP.
I have even included intl.so and extension=php_intl.dll in my php.ini file but couldn't figure out solution for this error.
this issue was happening to me some days ago. I had installed Ubuntu 18.04 and php 7.1.
I was trying to run the comman php cake.php bake in orden to use cakephp's console but I was getting the following error message:
You must enable the intl extension to use CakePHP.
This extension (intl) was installed for php 7.1 (php7.1-intl) but this message was appearing every time I used php cake.php bake
After some google searches, I saw that I have to install the extension but with the following command:
sudo apt-get install php-intl
The same issue happened with mbstring extension, I used the command:
sudo apt-get install php-mbstring
then I restarted the apache server with:
sudo service apache2 restart
It's difficult to pinpoint exactly what's wrong without seeing your system setup. However based on what was said in the question, you may be setting up the intl extension incorrectly.
First off, if your OS is Linux/macOS and the PHP extension is a shared library (i.e. has a .so extension) then the php.ini entry should be extension=intl.so not extension=php_intl.dll. Also make sure the intl.so file is in the directory configured under the ini entry extension_dir. Otherwise make sure the extension ini entry is fully qualified (e.g. extension=/path/to/extension/dir/intl.so).
If you are using a Linux OS that has a package manager such as Debian/Ubuntu, you may be able to more easily install the extension for the PHP packaged for that distro. For example, in Ubuntu/Debian the package php5-intl provides the intl extension for PHP5 (I assume it's something similar for PHP7 if you've enabled those repos).
If you build PHP from source, you can try bundling the extension into your PHP. See the instructions from the manual.
I faced the same issue.
I added extension="php_intl.dll" in php.ini and restarted the Apache server.
Now it is working.
I had the same issue. After starting from scratch, I did :
$ brew install php
$ composer install && composer update && composer dump-autoload --optimize
$ composer self-update && composer create-project --prefer-dist cakephp/app:^3.8 cms
$ cd cms
$ bin/cake server
And it was working !

How to stacically compile DBD::mysql and move the files on a shared hosting where i have my own perl installation

I have downloaded and installed locally on my Ubuntu ActiveState Perl(ActivePerl-5.14.1.1401-x86_64-linux-glibc-2.3.5-294969.tar.gz).
I did "~$ sudo apt-get install libmysqlclient-dev"
I downloaded from CPAN DBD::mysql
I read INSTALL.html
And here is my problem:
I am not sure how to compile a statically linked DBD::mysql which i can copy from my local ActivePerl installation to the same perl instalaltion but on my shared hosting provider mashine.
Note that the uploaded via ftp(no ssh there) perl directory structure works on the shared hosting (also x86_64-linux) after changing executable file permissions in ActivePerl/bin/ directory.
My CGI scripts run well under mod_cgi and mod_fast_cgi on the shared hosting.
I tried the advises in the installation document(INSTALL.html#source_installation) but no luck.
On another shared hosting with i586 Active Perl DBD::mysql just works because I first installed it locally using PPM and then uploaded via FTP. However there is no x86_64 PPM package provided by ActiveState.
Can sonmebody provide the magick spells for the commandline(ubuntu 11.04), something like:
me#mine:~$ mkdir /tmp/mysql-static
me#mine:~$ cp /usr/lib/libmysqlclien* /tmp/mysql-static
me#mine:~$ cd ~/install/Perl/DBD-mysql-4.019/
me#mine:~/install/Perl/DBD-mysql-4.019$ perl Makefile.PL --libs="-L/tmp/mysql-static -lmysqlclient"
me#mine:~/install/Perl/DBD-mysql-4.019$ make
me#mine:~/install/Perl/DBD-mysql-4.019$ make install
...
...hm :D seems it worked this time, but anyway I wrote all of the above... it might be useful to others. I will upload later today on the shared hosting to see if it works.
This works.
The only thing that one has to be aware is when using it on the shared hosting. You should connect via TCP instead of via Unix socket:
$dsn = "DBI:mysql:database=$database;host=127.0.0.1;port=3306";
$dbh = DBI->connect($dsn, $user, $password);
As written in the docs:
To connect to a MySQL server on localhost using TCP/IP, you must specify the hostname as 127.0.0.1 (with the optional port).

How to use Linux Xampp mysql_pdo with Symfony 2.0

I've got a serious problem.
I would like to use Doctrine 2 on my Symfony 2 projet.
I've change the php path from the app/console :
/opt/lampp/bin php
I've specify the good path for my mysql_pdo in /opt/lampp/etc/php.ini
pdo_mysql.default_socket = /opt/lampp/var/mysql/mysql.sock
and check to my php_info() for my pdo :
PDO
PDO support enabled
PDO drivers mysql, pgsql, sqlite, sqlite2
pdo_mysql
PDO Driver for MySQL enabled
Client API version mysqlnd 5.0.7-dev - 091210 - $Revision: 304625
$
Directive Local Value Master Value
pdo_mysql.default_socket /opt/lampp/var/mysql/mysql.sock /opt/lampp/var/mysql/mysql.sock
pdo_pgsql
PDO Driver for PostgreSQL enabled
PostgreSQL(libpq) Version 8.0.3
Module version 1.0.2
Revision $Id: pdo_pgsql.c 300351 2010-06-10 12:11:19Z iliaa $
Everything seems fine, but when I use this Symfony command :
php app/console doctrine:mapping:import WonderWBundle yml
It juste says :
[PDOException] could not find driver
I'm on Ubuntu 10.10
XAMPP for Linux 1.7.4 !
It seems that I've got everything to made Pdo work well but not on Symfony 2.
Does anyone could help ? Pleeeaaaassse (I'm going mad !!)
Thanks a lot :P
(P.S : Grrr cannot link my screenshots !)
Another reason could be related to PHP itself.
Various linux distros compile their php-cgi/fpm/apache and php-cli to use different php.ini files ( which actually makes sense )
Both ini files use to have their module configuration files included from subdirectories.
If you install an additional module manually, the `phpinfo()? viewed in a web browser may show the module, but programs executed on the commandline, just like Zend Framework app/console are using php-cli with another configuration.
e.g. for the apache module
/etc/php/php-apache/php.ini
/etc/php/php-apache/php.d/pdo_mysql.ini
for the commandline php
/etc/php/php-cli/php.ini
In this case you have to repeat your module configuration for the commandline client
/etc/php/php-cli/php.d/pdo_mysql.ini
The commandline php also has a phpinfo functionality, which you can use to verify your cli installation:
~ # php -i | grep "pdo"

how to fix this error " PHP Fatal error: Call to undefined function mysql_query() " in cake bake console [duplicate]

This question already has answers here:
Why shouldn't I use mysql_* functions in PHP?
(14 answers)
Closed 4 months ago.
I've seen this error in many places but the exact case.
I got this error while running the cake bake console, exactly after choosing C " controller " then choosing the default database config
i'm on Ubuntu 10.10 through Virtualbox
i'm using xampp - and installed the cakephp through the command apt-get install cakephp
here is the error
Use Database Config: (default/test)
[default] >
PHP Fatal error: Call to undefined function mysql_query() in /usr/share/php/cake/libs/model/datasources/dbo/dbo_mysql.php on line 588
Fatal error: Call to undefined function mysql_query() in /usr/share/php/cake/libs/model/datasources/dbo/dbo_mysql.php on line 588
Your issue is more than likely that some Linux distros have different php.ini's for Apache PHP and and PHP-CLI, it appears that your PHP-CLI (which cake baker will use) doesn't have the mysql_* functions enabled.
To fix, you'll need to locate the php.ini for the PHP CLI and uncomment the line which includes the mysql_* lib. should be something like "extension=mysql.so". To find the location of php.ini, run php -r 'phpinfo();' on the command line and scroll to the top to see the location of php.ini.
Reinstalling did the trick for me:
sudo apt-get remove php5-common
sudo apt-get install --reinstall php5-mysql
sudo apt-get install --reinstall php5-cli
(note: mine was not a live or system-critical php install - I was just trying to get phpsh working with some mysql code. ymmv.)
Another thing people usually miss out is to set the path of extension directory itself.
For example, look at the ini file at another thread. He had already uncommented the line extension=php_mysql.dll but had not set the appropriate extension_dir.
You need this line to be uncommented or added in:
extension_dir = "ext"
where ext is the path to the extension directory.
I used Ubuntu 10.04 and 11.04 and faced the same obstacle which has been annoying for quite a while, since I want to use bake for certain solutions.
To fix it you can open a terminal and type here:
php -i | grep 'Configuration File'
which yields something like this:
Configuration File (php.ini) Path => /usr/local/lib
Well and surprisingly enough this is not the default path to keep you php.ini file, it is rather /etc/php5/cli/
Now you can simply copy your php.ini into /usr/local/lib or see how to fix the Configuration File Path.
I assume you have php5-pgsql (using postgres) or php5-mysql (using MySql) installed. Otherwise you might set your Configuration File Path in any way