i have PHP Version 5.2.8 on my windows 2003 server, i am trying to connect with database
$dbh = new PDO("mysql:host=localhost;port=3306;dbname=$db_name", $db_user, $db_pass);
but when i use this statement i got following error
Fatal error: Uncaught exception 'PDOException' with message 'could not find driver'
in bin\db.php:14 Stack trace: #0 bin\db.php(14):
PDO->__construct('mysql:host=loca...', 'root', '123') #1
main.php(4): include_once('C:\Inetpub\wwwr...') #2
{main} thrown in bin\db.php on line 14
how can i fix this problem?
Thanks
You must remove the ; on this line in php.ini :
;extension=php_pdo_mysql.dll
extension=php_pdo_mysql.dll
If you're upgrading PHP, be sure to check your environment variable information, especially your `PATH, and reboot if you change it.
I was using a php.ini file from a different directory. As Sebastian Grignoli suggests, check your phpinfo() results for the location of the php.ini it's using.
Related
I need to use PHP PDO to connect to a MariaDB database to do work. But when I run the php file through the processor it throws an error:
Fatal error: Uncaught PDOException: could not find driver in C:\Users
\...\Documents\Visual Studio 2017\Projects\...\...
\dashboard.php:16
Stack trace:
#0 C:\Users\...\Documents\Visual Studio 2017\Projects\...
\...\dashboard.php(16): PDO->__construct('mysql:host=;dbn...',
NULL, NULL, Array)
#1 {main}
thrown in C:\Users\...\Documents\Visual Studio 2017\Projects
\...\...\dashboard.php on line 16
I have the PDO drivers enabled in php.ini
extension=php_pdo_mysql.dll
extension=php_pdo_sqlite.dll
extension=php_pdo_obdc.dll
Found the problem, when I ran phpinfo() inside the php file I found:
Loaded Configuration File => (none)
Turns out the process that was executing the file was ignoring the php.ini file.
I'm using odbc and XAMPP. I'm receiving the fatal error of could not find driver
Fatal error: Uncaught PDOException: could not find driver in C:\xampp\htdocs\index.php:5 Stack trace: #0 C:\xampp\htdocs\index.php(5): PDO->__construct('odbc:BEGIN') #1 {main} thrown in C:\xampp\htdocs\index.php on line 5
This is the code the error refering to :
$conn = new PDO ("odbc:BEGIN");
Is there any module that I should add to the php.ini like this answer or there are other solution?
You need to enable those extensions in order to have ODBC PDO driver working
php_pdo.dll
php_odbc.dll
php_pdo_odbc.dll
After enabling those extension as #Sarhan said, we need to restart Apache in order for it to work.
$con = mysql_connect('HOSTNAME', 'USER', 'PASSWORD');
I run with the above code and it shows the error below
Fatal error: Uncaught Error: Call to undefined function
mysql_connect() in
C:\xampp\htdocs\DatabaseIntegration-master\workshop_connect.php:3
Stack trace: #0 {main} thrown in
C:\xampp\htdocs\DatabaseIntegration-master\workshop_connect.php on
line 3
Fatal error: Uncaught Error: Call to undefined function mysql_connect() in
C:\xampp\htdocs\DatabaseIntegration-master\workshop_retrieve.php:3
Stack trace: #0 {main} thrown in
C:\xampp\htdocs\DatabaseIntegration-master\workshop_retrieve.php on
line 3
If you are use PHP 7+ MYSQL no longer exist, try MYSQLi
if you are using any 5.x version, follow below
Try checking if the PHP MySQL extension is enabled or not.
<?php
phpinfo();
?>
if you cannot find mysql extension there, theme mysql extension is not enabled.
Locate php.ini file, and edit it.
find the line
;extension=php_mysql.dll
and remove ; from the line
extension=php_mysql.dll
So I just finally installed the PDO drivers, and now I have another issue. When I try to use
<?php
$username = "root";
$password = "allen123";
$conn = new PDO('mysql:host=localhost;dbname=test', $username, $password);
?>
Just to connect to the DB, I get the following error
Fatal error: Uncaught exception 'PDOException' with message
'SQLSTATE[HY000] [2002] No such file or directory' in
/Users/idrisk/Colourity/site/index.php:4 Stack trace: #0
/Users/idrisk/Colourity/site/index.php(4):
PDO->__construct('mysql:host=loca...', 'root', 'allen123') #1 {main}
thrown in /Users/idrisk/Colourity/site/index.php on line 4
I've looked at other posts on SO about this issue, but they all seem different. Any ideas?
EDIT
So I installed the drivers via Macports and this is what I get once It was installed
To use mysqlnd with a local MySQL server, edit /opt/local/etc/php55/php.ini and set mysql.default_socket, mysqli.default_socket and pdo_mysql.default_socket to the path
to your MySQL server's socket file.
For mysql51, use /opt/local/var/run/mysql51/mysqld.sock
For mysql55, use /opt/local/var/run/mysql55/mysqld.sock
For mysql56, use /opt/local/var/run/mysql56/mysqld.sock
For mariadb, use /opt/local/var/run/mariadb/mysqld.sock
For percona, use /opt/local/var/run/percona/mysqld.sock`
The other answers say to use something else.
I have installed PDO_INFORMIX and CSDK already on CentOS5.6 32bits
and index.php have
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
$db = new PDO("informix:host=172.30.179.81; service=5000;database=cms; EnableScrollableCursors=1", "myuser", "mypassword");
print("OK");
?>
but i still got this error
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE=HY000, SQLDriverConnect: -11060 [Informix][Informix ODBC Driver]General error.' in /usr/local/apache/htdocs/index3.php:5 Stack trace: #0 /usr/local/apache/htdocs/index3.php(5): PDO->__construct('informix:host=1...', 'myuser', 'mypassword') #1 {main} thrown in /usr/local/apache/htdocs/index3.php on line 5
Have anyone know what it is ?
Thanks
Ouch! The standard technique for finding out more about errors is:
$ finderr -11060
-11060 General error.
An error occurred that has no specific SQL_STATE. In this case,
additional text is provided that identifies the source of the problem.
This IBM Informix CLI error code is the same as SQLSTATE value S1000.
$
That is not very helpful - to be polite about it.
There are spaces in the connect string; does removing them help at all?
Can you telnet to the host 172.30.179.81?
Can you telnet to the port (service) 5000 on the host?
Can you connect from this machine using any other Informix tool?
Can you connect from other machines using the same connect string?
In case of desparation, can you track down whether all the shared libraries are loading correctly?