Trying to connect PDO on a local server - php

I am trying to connecting PDO on my local server. I'm using Windows 7 Professional 64-bit and have AppServ installed. In a php document I use the following code for connection:
<?php
$dbh = new PDO('mysql:host=localhost;dbname=test', 'root', 'password');
?>
But the code turns out to be an error: Fatal error: Uncaught exception 'PDOException' with message 'could not find driver' in C:\AppServ\www\a.php:2
I checked phpinfo() and it shows that sqlite and sqlite2 are the only two databases installed in PDO. So how can I install MySQL PDO?

Thank you all. I just removed the semicolon in the php.ini file for MySQL and it works! The default location of php.ini file is in C:/Windows/.

Related

Unable to Connect to MySQL on Apache Server

I'm trying to setup a new local web server. Apache is already running and php is working. Mysql is installed. I can run mysql through the MySQL workbench. However, I am not able to connect to the MySQL from the php document.
First, the guides I looked at said to add the extension in php.ini. I went to php.ini-development and uncommented the line:
extension=mysqli
After restarting the server this didn't help. I also tried variations like extension=php_mysqli, and php_mysqli.dll.
I do in fact have the mysql dll on my computer. It is in:
C:\php\ext\php_mysqli.dll
My computer says the dll has not been accessed or modified since I downloaded it, so the Apache hasn't touched it at all.
Here is the code:
<?
$servername = "localhost";
$username = "root";
$password = "*************";
$conn = new mysqli($servername, $username, $password);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>
I get this error:
Fatal error: Uncaught Error: Class 'mysqli' not found in C:\Websites\x.php:14 Stack trace: #0 {main} thrown in C:\Websites\x.php on line 14
The MySQL is set to port 3306, and mysqli.default_port is set to 3306 in httpd.conf.
This is Windows 10. The MySQL version is 8.0.2. How can I make PHP use the mysql library/talk to MySQL?
EDIT:
Not the same as How to solve "Fatal error: Class 'MySQLi' not found"?.
I have tried the solutions there, but none of the answers worked so far.
First, be sure you're editing the "right" php.ini file. There can be several php.ini files on your system so execute this PHP code to see which php.ini is loaded in the context of your database connection script:
var_dump(php_ini_loaded_file());
Then, try to specify in this php.ini the absolute path to MySQLi DLL file like this:
extension=C:\php\ext\php_mysqli.dll
Note: Don't forget to restart Apache server after the modification of the php.ini.

php sqlite driver missing?

I am trying to connect to an existing database I created via DB browser for SQLite. It is saved as a file on my computer.
When using getAvailableDrivers, I am getting both MySQL and SQLite.
In phpinfo() I have the following entries:
PDO
PDO drivers -> MySQL, SQLite
pdo_sqlite
SQLite library -> 3.8.10.2
SQLite3
SQLite3 module version -> 0.7-dev
SQLite Library 3.9.10.2
SQLite3 extension dir -> c:\xampp\SQLite
I have written the following code to just establish connection:
<?php
phpinfo();
print_r(PDO::getAvailableDrivers());
$handler = new PDO('SQLite3:host=127.0.0.1;dbname=test', '', '');
?>
But when I try it I get the following error message:
Fatal error: Uncaught exception 'PDOException' with message 'could not find driver' in C:\xampp\htdocs\Ebsco\Users.php:4 Stack trace: #0 C:\xampp\htdocs\Ebsco\Users.php(4): PDO->__construct('SQLite3:host=12...', '', '') #1 {main} thrown in C:\xampp\htdocs\Ebsco\Users.php on line 4
I have searched several places online and several answers on Stack Overflow, but they did not help with a solution.
Any idea what could be causing this?
I noticed that the dir in the error message is not the same directory which I specified in the php.ini (which is also returned by phpinfo();), but I'm not sure if that is the cause, and if so what is causing it to search for the driver in that location.

Warning: Cannot connect to database (connecting to 3.22, 3.23 & 4.0 is not supported) SQLSTATE[HY000] [2054]

While I was coding yesterday, suddenly the following error message came up:
Warning: PDO::__construct(): Connecting to 3.22, 3.23 & 4.0 is not supported. Server is 3.23.58-log in /classes/DB.php on line 18
SQLSTATE[HY000] [2054] Connecting to 3.22, 3.23 & 4.0 servers is not supported
Line 18 of my DB.php:
$this->_pdo = new PDO(
'mysql:host='.config::get('mysql/host').
';dbname='.config::get('mysql/db'),
config::get('mysql/username'),
config::get('mysql/password')
);
So basically - if I got it right - the warning is saying that my mysql database is outdated. Doesn't make sense at all as it worked with PDO before and I didn't change anything in DB.php or Init.php.
Server Version: 4.1.22-log
MySQL-Client-Version: 5.1.61
phpMyAdmin: 2.11.11.3
php-Version: 5.6.12
Also, I've checked in domainfactory and there it clearly says my php Version is 5.6.12 and my MySQL Version is 5.1.16
So I feel like there is something wrong with my webhoster but I decided to ask here at first. Anything wrong with my settings?
This error indicates that an too old MySql version is used.
Often DomainFactory users face the error, when trying to connect to 127.0.0.1
In case you are using Domainfactory make sure to connect to "mysql5.[yourdomain].[yourtld]".

connecting php 5.2.4 with MSSQL server 2008 using pdo

I use php 5.2.4, and I am trying to connect with the MSSQL database, without success.
My php info show this:
mssql
MSSQL Support enabled
Active Persistent Links 0
Active Links 0
Library version 7.0
pdo_mssql
PDO Driver for MSSQL DB-lib enabled
Flavour MSSQL_70
My PHP code is: as follow:
$db = new PDO("sqlsrv:Server= servername\sqlservername;Database=mydb", "myuser", "mypass");
var_dump($db);
The error message displays:
Fatal error: Uncaught exception 'PDOException' with message 'could not find driver'
Anyone have idea what is wrong?

Fatal error: Uncaught exception 'PDOException' with message 'could not find driver' using IBM Informix and WAMP

I got error ( Fatal error: Uncaught exception 'PDOException' with message 'could not find driver' in C:\wamp\www\test.php on line 30) when i run my php page using wamp server.
First I introduce the technology i used.
1) Adobe dreamviewer CS6
2) WAMP server 2.0
3)IBM Informix 64 bit
Steps i followed
Install IBM Informix 64 bit
make ODBC connection (System DNS) successsful
download php_pdo.dll and php_PDO_Informix.dll and paste these .dll on "C:\wamp\bin\php\php5.4.12\ext"
add below lines in php.ini below extension
extension=php_pdo.dll
extension=php_pdo_informix.dll
*create below php code for connection test with IBM informix
<?php $db = new PDO("informix:host=10.81.32.12; service=1504;
database=db_cra; server='servername'; protocol=onsoctcp;
EnableScrollableCursors=1", "Userid", "Pasw") or die("Could not connect to data); ?>
restart WAMP server and execute this page
then i got this Fatal error: Uncaught exception 'PDOException' with message 'could not find driver'
Please help..I'm totally new for this Technology,
Let me know any thing you require from my side.
Perhaps try with a DSN? http://php.net/manual/en/ref.pdo-informix.connection.php
$db = new PDO("informix:DSN=Infdrv33", "", "");
where Infdrv33 is replaced by the name of the System DSN you tested.

Categories