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?
Related
I've installed the php5-odbc library.
Trying to connect to a .mdb file but keep getting error Data source name not found, and no default driver specified.
Code:
$dbName = "../../../var/Import/PartsPlaceDB.mdb";
if (!file_exists($dbName)) {
die("Could not find database file.");
}
$db = new PDO("odbc:DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=$dbName; Uid=; Pwd=;");
Outputs:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[IM002] SQLDriverConnect: 0 [unixODBC][Driver Manager]Data source name not found, and no default driver specified' in [...]
PDO Drivers:
foreach(PDO::getAvailableDrivers() as $driver)
{
echo $driver.'<br />';
}
Output:
mysql
odbc
sqlite
The problem is recurrent with 64-bit version. It looks like your code only work on Windows 32-bit.
To solve the problem, you might install this tool: Microsoft Access Database Engine 2010 Redistributable. I had the same problem for months but this tool solved mine.
I guess you're doing the location wrong?
Instead of this
$dbName = "../../../var/Import/PartsPlaceDB.mdb";
Why not do it like this
$dbName = "..\..\..\var\Import\PartsPlaceDB.mdb";
I am receiving an error as below:
PHP Fatal error: Uncaught exception 'PDOException' with message
'SQLSTATE[08001]: [Microsoft][ODBC Driver 11 for SQL Server]SQL Server
Network Interfaces: Connection string is not valid [87]. '
My codes are as follow:
$this->link = new PDO(
"sqlsrv:server=$this->serverName:$this->port;Database=$this->db",
"$this->uid",
"$this->pwd"
);
I wish someone can enlighten me on what is causing this error. Before that I was using dblib instead of sqlsrv.
"dblib:host=$this->serverName:$this->port;dbname=$this->db"
I am using XAMMP with Apache 2.4.12 and PHP 5.5.24 (they are all x86). I have php_pdo_sqlsrv_55_ts.dll and php_sqlsrv_55_ts.dll. I am also using Microsoft ODBC Driver 11 for SQL Server-x64.
Change it to:
$this->link = new PDO(
"sqlsrv:Server={$this->serverName},{$this->port};Database={$this->db};",
$this->uid,
$this->pwd
);
The default SQL Server port is 1433. Note the curly brackets, they allow for class variables.
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/.
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.
I need to connect to a MS SQLServer 2008 service from PHP on Ubuntu, and I would like to do so using PDO. I believe I have installed all the prerequisite libraries, and I am indeed able to connect using tsql on the command line and using mssql_connect() in code. I can't figure out what the proper DSN is, or if there are any additional PDO-specific configuration steps I am missing.
I am using the following DSN (where $db* variables are populated with their appropriate values):
odbc:Driver=FreeTDS;SERVER=$dbServer;DATABASE=$dbSchema;UID=$dbUser;PWD=$dbPasswd"
My error message is:
PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[IM002] SQLDriverConnect: 0 [unixODBC][Driver Manager]Data source name not found, and no default driver specified' in /home/timothy/test.php:4
Stack trace:
#0 /home/timothy/test.php(4): PDO->__construct('odbc:Driver=Fre...')
#1 {main}
thrown in /home/timothy/test.php on line 4
What additional configuration steps have I over looked?
Thanks in advance.
You shouldn't need any additional configuration if you can connect with tsql and the mssql extension. You probably just don't have the correct dsn. This documentation should help. Try new PDO("dblib:host=xx.xx.xx.xx;dbname=mydatabase", "username", "password");