ERROR: could not find driver (HELP)

Problems with the Windows version of XAMPP, questions, comments, and anything related.

ERROR: could not find driver (HELP)

Postby Epiales » 09. May 2018 23:24

I've been using XAMPP for years. I just upgraded today so that I could start my next project using PDO. But I cannot figure out how to get it working. Online videos and here and still can't get it.

Here is my connection:

Code: Select all
<?php
$db_host = "localhost";
$db_user = "epiales";
$db_pass = 'testing';
$db_name = "testing";

/* $con = mysqli_connect($mysql_hostname, $mysql_user, $mysql_password, $mysql_database)  */

/* or die("Oops some thing went wrong");
 */
 
 try {
 $con = new PDO("mysqli:host=($db_host);dbname=($db_name)", $db_user, $db_pass);
 $con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}   catch(PDOException $e) {
    echo 'ERROR: ' . $e->getMessage();
}

?>


Here is my ini file...

Code: Select all
extension=bz2
extension=curl
extension=fileinfo
extension=gd2
extension=gettext
;extension=gmp
;extension=intl
;extension=imap
;extension=interbase
;extension=ldap
extension=mbstring
extension=exif      ; Must be after mbstring as it depends on it
extension=mysqli
;extension=oci8_12c  ; Use with Oracle Database 12c Instant Client
;extension=openssl
;extension=pdo_firebird
extension=pdo_mysql
;extension=pdo_oci
;extension=pdo_odbc
extension=pdo_pgsql
extension=pdo_sqlite
;extension=pgsql
;extension=shmop


What am I doing wrong? I've restarted many times and tried putting .dll extension on the files and still nothing. I would appreciate any help, as this is really dire that I get this working asap. Thank you and blessings for anyone takin their time to help facilitate this problem.

I did think that the new version, out of the box would of been sufficient? Also, I"m using Windows 10 and of course the php, mysql that came with XAMPP. Thank you again.

Blessings,

EPIALES
Epiales
 
Posts: 8
Joined: 09. May 2018 23:13
XAMPP version: Latest 7.2.4
Operating System: Windows 10

Re: ERROR: could not find driver (HELP)

Postby Altrea » 10. May 2018 11:07

Hi,

You nee to use mysql into your PDO connection string, not mysqli. These are two completely different things.

Best wushes,
Altrea
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11926
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64

Re: ERROR: could not find driver (HELP)

Postby Epiales » 10. May 2018 16:53

Altrea wrote:Hi,

You nee to use mysql into your PDO connection string, not mysqli. These are two completely different things.

Best wushes,
Altrea



Hmm, not sure what you mean. Every example I have seen shows the mysqli for PDO? Maybe you looked at the code that was commented out? Here's what I have.

Code: Select all
<?PHP

$db_user = 'root';
$db_pass = '';
$db_name = 'testing';
$db_host = 'localhost';

try {
   $con = new PDO("mysqli:host=($db_host);dbname=($db_name)", $db_user, $db_pass);
   $con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e) {
   echo 'ERROR: ' . $e->getMessage();
}

?>


I have tried localhost, 127.0.0.1
I have downloaded the 7.2 drivers for sqlsrv

It shows on my dashboard in Xampp:
PDO enabled: mysql, sqlite
PDO_MYSQL enabled: mysqlnd 5.0.12-dev
PDO_SQLITE enabled: 2.10.1
Loaded Configuration File: C:\xampp\php\php.ini

So I'm really at a loss. I don't know anything about PDO, but figured since I"m starting a very huge business website, I would rather start it using PDO, which will probably be around a long time. Thank you for accepting the post and helping.
Epiales
 
Posts: 8
Joined: 09. May 2018 23:13
XAMPP version: Latest 7.2.4
Operating System: Windows 10

Re: ERROR: could not find driver (HELP)

Postby Nobbie » 10. May 2018 17:47

Epiales wrote:Hmm, not sure what you mean.


You should NOT use mysqli. Use mysql (without i in the end) instead).

Epiales wrote:Every example I have seen shows the mysqli for PDO?


Maybe. But in your Xampp Installation there is no mysqli for PDO included. Instead mysql for PDO is included.

Epiales wrote:Maybe you looked at the code that was commented out?


No, i dont think so. You showed code showing PDO mysqli, but PDO mysqli not in your Xampp installation. See here:

It shows on my dashboard in Xampp:
PDO enabled: mysql, sqlite
PDO_MYSQL enabled: mysqlnd 5.0.12-dev
PDO_SQLITE enabled: 2.10.1


Do you see? There is "PDO MYSQL enabled". There is NO mysqli.

Epiales wrote:So I'm really at a loss. I don't know anything about PDO


Maybe, that is everybodys problem. You should learn about PDO and learn about mysql interface. Search for PDO mysql examples.
Nobbie
 
Posts: 13170
Joined: 09. March 2008 13:04

Re: ERROR: could not find driver (HELP)

Postby Epiales » 10. May 2018 18:02

I have tried removing the I as you stated and received same message. I have also added the extension with the msqli on it. I have tried with and without the I.

When I take the i off of mysqli, then I get this error as well

ERROR: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: No such host is known.

localhost is the host.. if I change to 127.0.0.1, I get the same error.

I have been looking at PDO examples for two days now. None of the examples are working for me. I can write mysqli and connect without any difficulties.

Sorry if I'm not understanding, but I have really been on the internet almost 2 days non stop trying to figure it out with tons of examples, in which, none of them work.
Epiales
 
Posts: 8
Joined: 09. May 2018 23:13
XAMPP version: Latest 7.2.4
Operating System: Windows 10

Re: ERROR: could not find driver (HELP)

Postby Altrea » 10. May 2018 20:05

Epiales wrote:Hmm, not sure what you mean. Every example I have seen shows the mysqli for PDO?

Show us the examples you found.
This cannot be true for one simple reason: PDO knows very specific drivers supported for PDO. mysql is listed there but not mysqli
http://php.net/manual/en/pdo.drivers.php

Epiales wrote:Maybe you looked at the code that was commented out? Here's what I have.

No. I mean the following line
Code: Select all
$con = new PDO("mysqli:host=($db_host);dbname=($db_name)", $db_user, $db_pass);


Epiales wrote:I have tried localhost, 127.0.0.1

The host is not your problem, it is the database driver used in your connection string.

Epiales wrote:I have downloaded the 7.2 drivers for sqlsrv

This will not help.

Epiales wrote:I have tried removing the I as you stated and received same message.

Show us this specific code and the related error message.

Epiales wrote:I have also added the extension with the msqli on it. I have tried with and without the I.

There is no mysqli database driver for PDO supported.

Epiales wrote:When I take the i off of mysqli, then I get this error as well

ERROR: SQLSTATE[HY000] [2002] php_network_getaddresses: getaddrinfo failed: No such host is known.

localhost is the host.. if I change to 127.0.0.1, I get the same error.

Are you sure localhost is the host? in your connection string you used rounded brackets around your variables for db_host and db_name, so they will get entered in your connection string too.
But that is a different issue and cannot be present the same time the first issue occurs.
We don't provide any support via personal channels like PM, email, Skype, TeamViewer!

It's like porn for programmers 8)
User avatar
Altrea
AF Moderator
 
Posts: 11926
Joined: 17. August 2009 13:05
XAMPP version: several
Operating System: Windows 11 Pro x64

Re: ERROR: could not find driver (HELP)

Postby Nobbie » 10. May 2018 20:29

Epiales wrote:Sorry if I'm not understanding, but I have really been on the internet almost 2 days non stop trying to figure it out with tons of examples, in which, none of them work.


Two days only? It took me a couple of years(!) to become a skilled PHP/MySQL Programmer. You are just in the very very very very beginning. Two days is NOTHING!
Nobbie
 
Posts: 13170
Joined: 09. March 2008 13:04

Re: ERROR: could not find driver (SOLVED)

Postby Epiales » 10. May 2018 20:36

Nobbie wrote:
Epiales wrote:Sorry if I'm not understanding, but I have really been on the internet almost 2 days non stop trying to figure it out with tons of examples, in which, none of them work.


Two days only? It took me a couple of years(!) to become a skilled PHP/MySQL Programmer. You are just in the very very very very beginning. Two days is NOTHING!


As stated in my first post, I've used XAMPP for years. I'm pretty well able to do mysql and mysqli. I've never done PDO before. It's totally different for me. But all in all, I figured it out. I was using ( )'s on my query to the database.

Code: Select all
   $con = new PDO("mysql:host=($db_host);dbname=($db_name)", $db_user, $db_pass);

and changed it to this:

Code: Select all
   $con = new PDO("mysql:host=$db_host;dbname=$db_name", $db_user, $db_pass);

It all works now. Thank you for your time and help on solving this issue. I still have much to learn in PDO though. I can only connect to DB lol. I have to relearn all the queries to select, update, delete.. etc... But google is my friend on that lol. Thanks again.
Epiales
 
Posts: 8
Joined: 09. May 2018 23:13
XAMPP version: Latest 7.2.4
Operating System: Windows 10


Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 76 guests