Why are PHP 7 PDO drivers missing? - php

Okay, so. I have PDO connection on MySQL database on local server. This is the code for it
<?php
$servername = "localhost";
$username = "root";
$password = "";
try {
$dbh = new PDO('localhost:host=$servername;dbname=test', $username, $password);
$dbh = null;
} catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}
?>
When I open the page it gives me this error.
Error!: could not find a driver
It is obvious that drivers are missing but I have no idea how to install them. I already used
sudo pacman -S php
sudo pacman -S php-sqlite
sudo pacman -S mysql
Maybe I forgot some. Here is my /etc/php/php.ini file's content
;;;;;;;;;;;;;;;;;;;;;;
; Dynamic Extensions ;
;;;;;;;;;;;;;;;;;;;;;;
; If you wish to have an extension loaded automatically, use the following
; syntax:
;
; extension=modulename
;
; For example:
;
; extension=mysqli
;
; When the extension library to load is not located in the default extension
; directory, You may specify an absolute path to the library file:
;
extension=/path/to/extension/mysqli.so
;
; Note : The syntax used in previous PHP versions ('extension=<ext>.so' and
; 'extension='php_<ext>.dll') is supported for legacy reasons and may be
; deprecated in a future PHP major version. So, when it is possible, please
; move to the new ('extension=<ext>) syntax.
;
;extension=bcmath
;extension=bz2
;extension=calendar
extension=curl
;extension=dba
;extension=enchant
;extension=exif
;extension=ftp
extension=gd
;extension=gettext
;extension=gmp
;extension=iconv
;extension=imap
;extension=intl
;extension=sodium
;extension=ldap
;extension=mysqli
;extension=odbc
;zend_extension=opcache
;extension=pdo_dblib
extension=pdo_mysql
extension=bz2.so
extension=mcrypt.so
extension=mysqli
;extension=pdo_odbc
;extension=pdo_pgsql
extension=pdo_sqlite
;extension=pgsql
;extension=pspell
;extension=shmop
;extension=snmp
;extension=soap
;extension=sockets
extension=sqlite3
;extension=sysvmsg
;extension=sysvsem
;extension=sysvshm
;extension=tidy
;extension=xmlrpc
;extension=xsl
extension=zip
It didn't let me upload the whole file so here is only part of it. If you need more details I will gladly add them in comments.
Maybe I am missing something obvious but I can't find it for a few days.
EDIT
Sorry for not pointing this out.
I am using Manjaro Linux OS

When creating the connection, your DSN has localhost as the database type...
$dbh = new PDO('localhost:host=$servername;dbname=test', $username, $password);
from the manual
$dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass);
Also as you use single quotes, the servername will not be replaced, so use
$dbh = new PDO("mysql:host=$servername;dbname=test", $username,

Try this
sudo apt-get install php7-mysql

I think PDO extensions are missing. Add the below extensions and restart your server
For windows server -
extension=php_pdo.dll
extension=php_pdo_mysql.dll
For Linux server -
extension=pdo.so
extension=pdo_mysql.so

Related

Laravel Lumen image validation is not working

I'm validating a request as an image, but crashes saying:
"Unable to guess the MIME type as no guessers are available (have you
enable the php_fileinfo extension?)".
In php.ini I don't have a extension=php_fileinfo, but I do have a extension=fileinfo uncommented line (I see Lumen put this and other dependencies without the 'php_'). I also try adding extension=php_fileinfo, but when I restart Apache from XAMPP it crashes because it doesn't find that dependency. What should I do?
The code:
function updateProfilePicture(Request $request) {
$this->validate($request, [
'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048'
]);
//...
The php.ini section where fileinfo dependency is:
;;;;;;;;;;;;;;;;;;;;;;
; Dynamic Extensions ;
;;;;;;;;;;;;;;;;;;;;;;
; If you wish to have an extension loaded automatically, use the following
; syntax:
;
; extension=modulename
;
; For example:
;
; extension=mysqli
;
; When the extension library to load is not located in the default extension
; directory, You may specify an absolute path to the library file:
;
; extension=/path/to/extension/mysqli.so
;
; Note : The syntax used in previous PHP versions ('extension=<ext>.so' and
; 'extension='php_<ext>.dll') is supported for legacy reasons and may be
; deprecated in a future PHP major version. So, when it is possible, please
; move to the new ('extension=<ext>) syntax.
;
; Notes for Windows environments :
;
; - Many DLL files are located in the extensions/ (PHP 4) or ext/ (PHP 5+)
; extension folders as well as the separate PECL DLL download (PHP 5+).
; Be sure to appropriately set the extension_dir directive.
;
extension=bz2
extension=curl
extension=fileinfo
extension=gd2
extension=gettext
Maybe is it related to that disclaimer about how to set the dependencies directives? (I'm not sure because extension=fileinfo was already in the file as a default)
I'm using windows 10 and I found the file in C:\xampp\php\ext\php_fileinfo.dll
I found the problem. I had another php.ini file with the commented line ;extension=fileinfo in C:\php\php.ini (the one I was opening was in C:\xampp\php\php.ini). Now I restarted Apache and it's working!

Connection falied: could not find driver

I'm on Windows 10 and I'm using WAMP. I am trying to create a login form with prepared PDO statements. Below is the code to my connect.php script that is issuing the error: "Connection failed: could not find driver".
<?php
$server = 'localhost';
$username = 'root';
$password = '';
$db = 'login';
try{
$conn = new PDO("mysqli:host=$server;dbname=$db", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected Successfully";
}catch(PDOException $e){
echo "Connection falied: " . $e->getMessage();
}
?>
This is a list from my php.ini file that shows and DLLs associated with pdo
extension=php_openssl.dll
extension=php_pdo_firebird.dll
extension=php_pdo_mysql.dll
extension=php_pdo_oci.dll
extension=php_pdo_odbc.dll
extension=php_pdo_pgsql.dll
extension=php_pdo_sqlite.dll
extension=php_pdo_mysql.dll
extension=php_pdo.dll
extension=php_pdo_pgsql.dll
extension=php_pdo_sqlite.dll
extension=php_pgsql.dll
;extension=php_shmop.dll
WAMP says "no dll file" for:
-php_mysqli
-php_pdo
I have the "php_pdo" dll file in wamp/bin/php5.6.25/ and in wamp/bin/php5.6.25/ext/ just in case.
I can't find a download for php_mysqli but I don't think I need that for PDO, though it would be nice to have if anyone has a download link.
So my question is, did I just install the dll file into the wrong directory, or what? I'm not sure what to do, But I just installed WAMP and I can't use PDO. Should I use another client(I'm not sure what they are called).
I think you have a typo, try mysql instead of msqli:
$conn = new PDO("mysql:host=$server;dbname=$db", $username, $password);
Also from comments:
Try to put this in the php.ini : extension_dir = "c:\php5\ext" and point to the extension
move php_pdo.dll before the other PDO extensions, and restart WAMP
Edit: I decided to change my answer to be a community wiki, since I feel there should not be any rep that should come of this. Plus, the question being a typo on more than one count.
Original answer:
The syntax is:
mysql:host
and not mysqli. I hope this isn't another "typo" as per your original post https://stackoverflow.com/revisions/40444027/1 of new PDO("msqli:host
$dbh = new PDO('mysql:host=localhost;dbname=test', $user, $pass);
As per the manual:
http://php.net/manual/en/pdo.connections.php
Note: Wamp should be ready to use "out of the box" and not require any drivers to be added.
I use Wamp also and xampp and never had a problem.
Plus, Wamp installation comes in different flavours (32 and 64 bit), so make sure you chose the right one.
http://www.wampserver.com/en/
You can also try installing xampp
https://www.apachefriends.org/
Use error reporting also, which would have been of help here:
http://php.net/manual/en/function.error-reporting.php

Failed to connect mysql in centos 6.5

I'm using php-mysql-apache in centos 6.5 system all requirements are exists, i think i can publish my html files in localhost but when i try to connect to mysql in php script. It doesn't appear and it shows mysql connection error.
# rpm -qa |grep php
php-pdo-5.3.3-26.el6.x86_64
php-common-5.3.3-26.el6.x86_64
php-5.3.3-26.el6.x86_64
php-mysql-5.3.3-26.el6.x86_64
php-cli-5.3.3-26.el6.x86_64
php-ldap-5.3.3-26.el6.x86_64
# rpm -qa |grep mysql
mysql-libs-5.1.71-1.el6.x86_64
mysql-community-release-el6-5.noarch
mysql-5.1.71-1.el6.x86_64
mysql-server-5.1.71-1.el6.x86_64
php-mysql-5.3.3-26.el6.x86_64
I also checked my mysql password and username are correct i try to connect as below :
$connect= mysql_connect("localhost","root","password");
if(!$connect){
echo "Failed to connect to MySQL " ;
}
Also "dynamic extensions" part of php.ini file as below :
;;;;;;;;;;;;;;;;;;;;;;
; Dynamic Extensions ;
;;;;;;;;;;;;;;;;;;;;;;
; If you wish to have an extension loaded automatically, use the following
; syntax:
;
; extension=modulename.extension
;
; For example
;
; extension=msql.so
;
; ... or with a path:
;
; extension=/path/to/extension/msql.so
;
; If you only provide the name of the extension, PHP will look for it in its
; default extension directory.
extension=mysql.so
extension=mysqli.so
;;;
; Note: packaged extension modules are now loaded via the .ini files
; found in the directory /etc/php.d; these are loaded by default.
;;;;
I added this lines by hand;
extension=mysql.so
extension=mysqli.so
So where is my fault can do you have idea for run my php script in localhost?
Don't use mysql_connect as it is deprecated, use MySQLi or PDO to connect – it's really a pain, but check your Apache error log or enable PHP to show all errors in your scripts and it may help.

Debugging PHP ADODB.Connection

I am having a trouble to connect to MS SQL2000 with PHP through COM library.
The message I am getting is:
Could not establish a database connection exception 'com_exception'
with message 'Source: Microsoft OLE DB Provider for ODBC Drivers
Description: [Microsoft][ODBC SQL Server Driver][DBMSLPCN]SQL Server
does not exist or access denied.....
I have read through many posts and couldn't find any straight forward sample how to setup PHP in order to connect easily. These are the steps I've taken so far:
1) running MSSQL2000 with TCP/IP and Named Pipes enabled, listening on port 1433
2) installed PHP Version 5.4.16 TS
3) I have the following extensions enabled (related to mssql):
extension=php_com_dotnet.dll
extension=php_pdo_sqlsrv_53_ts_vc9.dll
extension=php_sqlsrv_53_ts_vc9.dll
extension=php_pdo_mssql.dll
extension=php_pdo_odbc.dll
4) I have checked for the COM windows permissions
5) I am sure I have provided the correct database/instance, username, password for the connection string.
6) when I instantiate the COM object with:
$connection = new COM("ADODB.Connection");
print_r($connection);
...I get the "com Object" output response, meaning the class seems to work fine.
What have I overlooked ? I have to connect through ADODB since the whole site I am working on is build on it. Is there a way to debug this? Any help is appreciated.
PROBLEM SOLVED!
After a few days of figuring this out and reinstalling virtually everything including Apache, different PHP and MSSQL versions I have come up with the following. I am not claiming this to be the best solution but it works:
Functional environment:
1) Windows Azure Server with MSSQL 2012
2) Apache 2.2 PHP 5.3.28 - installer: php-5.3.28-Win32-VC9-x86.msi downloaded from:
http://windows.php.net/download/
PHP Extensions (I am listing all but you need just the last few):
[PHP_BZ2]
extension=php_bz2.dll
[PHP_CURL]
extension=php_curl.dll
[PHP_ENCHANT]
extension=php_enchant.dll
[PHP_FILEINFO]
extension=php_fileinfo.dll
[PHP_GD2]
extension=php_gd2.dll
[PHP_GETTEXT]
extension=php_gettext.dll
[PHP_GMP]
extension=php_gmp.dll
[PHP_IMAP]
extension=php_imap.dll
[PHP_INTL]
extension=php_intl.dll
[PHP_LDAP]
extension=php_ldap.dll
[PHP_MBSTRING]
extension=php_mbstring.dll
[PHP_MYSQL]
extension=php_mysql.dll
[PHP_MYSQLI]
extension=php_mysqli.dll
[PHP_OCI8]
extension=php_oci8.dll
[PHP_OCI8_11G]
extension=php_oci8_11g.dll
[PHP_OPENSSL]
extension=php_openssl.dll
[PHP_PDO_MYSQL]
extension=php_pdo_mysql.dll
[PHP_PDO_OCI]
extension=php_pdo_oci.dll
[PHP_PDO_ODBC]
extension=php_pdo_odbc.dll
[PHP_PDO_PGSQL]
extension=php_pdo_pgsql.dll
[PHP_PDO_SQLITE]
extension=php_pdo_sqlite.dll
[PHP_PGSQL]
extension=php_pgsql.dll
[PHP_SHMOP]
extension=php_shmop.dll
[PHP_SNMP]
extension=php_snmp.dll
[PHP_SOAP]
extension=php_soap.dll
[PHP_SOCKETS]
extension=php_sockets.dll
[PHP_SQLITE]
extension=php_sqlite.dll
[PHP_SQLITE3]
extension=php_sqlite3.dll
[PHP_SYBASE_CT]
extension=php_sybase_ct.dll
[PHP_TIDY]
extension=php_tidy.dll
[PHP_XMLRPC]
extension=php_xmlrpc.dll
[PHP_XSL]
extension=php_xsl.dll
[PHP_EXIF]
extension=php_exif.dll
php_sqlsrv_53_ts_vc9.dll
php_pdo_sqlsrv_53_ts_vc9.dll
extension=php_com_dotnet.dll
The php_pdo_sqlsrv_53_ts_vc9.dll extension pack was downloaded from: http://www.microsoft.com/en-us/download/details.aspx?id=20098
The extension=php_com_dotnet.dll downloaded from: http://originaldll.com/file/php_com_dotnet.dll/29343.html (cannot verify how secure this file is but it works)
The MSSQL 2012 needs to be set as follows:
when creating your database, open the management studio and right click the database instance in the left tree. Make sure that under the properties->security tab you select: "SQL Server and Windows Authentication Mode". Without this you will never connect if you are using the standard username / password method.
Then proceed with creating the database schema and under the main security tab create the new user with username/password related to this database. Make sure you set all permission right i.e: owner, datareader, datawriter.
The PHP connection script I used is as follows:
*===============================================*
function openConnection() {
$dbaseServer = "instance name";
$dbaseIp = "127.0.0.1";
$dbasePort = "1433";
$dbaseName = "databsse name";
$dbaseUser = "username";
$dbasePassword = "password";
$connectionString = ""
."Driver={SQL Server};"
."Network=DBMSSOCN;"
."Server=$dbaseServer;"
."Address=$dbaseIp:$dbasePort;"
."Database=$dbaseName;"
."Uid=$dbaseUser;"
."Pwd=$dbasePassword";
try {
$connection = new COM("ADODB.Connection");
$connection->ConnectionTimeout = 60;
$connection->Open($connectionString);
return $connection;
} catch (exception $e) {
echo "Could not connect - $e";
exit;
}
}
// test query
//===========
$sql = "SELECT * FROM [dbname].[dbo].[tablename]";
$connection = openConnection();
// unnecessary but in my case more time is needed.
$connection->CommandTimeout = 240;
$recordset = $connection->Execute($sql);
if (!$recordset) { $connection->Close(); die("Request failed!"); }
if (!$recordset->EOF) {
while (!$recordset->EOF) {
$test[] = $recordset[0]->value;
$recordset->MoveNext();
}
}
print_r($test);
$connection->Close();
--
I think that's it. Please feel free to correct my post and/or improve it :)

How to enable mysqli on XAMPP?

By seeing suggestions throughout the Internet I tried to convert all my queries to mysqli.
But mysqli is not working in my XAMPP. I checked my PHP folder and there is a php_mysqli.dll file... still it doesn't work
Have you declare it to php.ini to load it? If no, try find this in php.ini and add php_mysqli.dll
;;;;;;;;;;;;;;;;;;;;;;
; Dynamic Extensions ;
;;;;;;;;;;;;;;;;;;;;;;
; If you wish to have an extension loaded automatically, use the following
; syntax:
;
; extension=modulename.extension
;
; For example, on Windows:
;
; extension=msql.dll
;
; ... or under UNIX:
;
; extension=msql.so
;
; ... or with a path:
;
; extension=/path/to/extension/msql.so
;
; If you only provide the name of the extension, PHP will look for it in its
; default extension directory.
;
; Windows Extensions
; Note that ODBC support is built in, so no dll is needed for it.
; Note that many DLL files are located in the extensions/ (PHP 4) ext/ (PHP 5)
; extension folders as well as the separate PECL DLL download (PHP 5).
; Be sure to appropriately set the extension_dir directive.
extension= php_mysqli.dll
Goto the directory phpMyAdmin, find there is a file with name config.inc.php, open the file and find a line there as:
$cfg['Servers'][$i]['extension'] = 'mysql';
just change mysql to mysqli.
Another thing that might be blocking the msqli dll from loading could be user right issues on your local webserver, make sure the \User can read the ext folder, that was what worked for me
I think you should use XAMPP 1.8.3-1, XAMPP 1.8.2-2, XAMPP 1.8.1.
Because these xampp versions also support Mysqli by default.

Categories