I have to establish a connection via PHP to a Access Database, but everytime I try I get this error:
Fatal error: Uncaught exception 'com_exception'
With message:
'Source: Microsoft OLE DB
Service ComponentsDescription: Das Format der Initialisierungszeichenfolge entspricht nicht
den OLE DB-Angaben.' in E:\path\to\phpfile.php:93
Stack trace: #0 E:\path\to\phpfile.php(93): com->Open('DRIVER={Microso...') #1 {main} thrown in
The German text means something like "the format of the initialization string is not common of the OLE DB statements.
My connection code looks like
$db = 'DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("\") & ("\\db\\db.mdb") & ";"';
$conn = new COM("ADODB.Connection");
$conn->Open($db);
I can't figure out what's wrong. In pure ASP it works fine, but not in PHP.
Thanks in advance
Instead of using the "ADODB.Connection" module use PDO since it's currently the best option out there and is a best practice, Here is the documentation: http://php.net/manual/en/book.pdo.php
But if PDO isn't for you then see ODBC (PDO RECOMMENDED) which is a native PHP module. Here is the documentation: http://php.net/manual/en/book.uodbc.php
To start a connection you would do this: $connection = odbc_connect("Driver={Microsoft Access Driver (*.mdb)};Dbq=$mdbFilename", $user, $password);
Use PDO instead. It can connect via ODBC:
$pathToMDB = "path/to/db.mdb";
$db = new PDO("odbc:Driver={Microsoft Access Driver (*.mdb)};Dbq=$pathToMDB", 'admin');
Related
In php and mysql we use mysqli_error(connection); to show error but how to show error while php mongoDB connection goes wrong. $m = new MongoClient();
please help..!
Use the MongoConnectionException class..
This exception gets thrown when you have connection issues.
I'm trying to get PDO connecting to an SQL server to enter READ UNCOMMITTED, according to various sources (https://msdn.microsoft.com/en-us/library/cc296183(v=sql.105).aspx) this is how you do it.
$pdo = new PDO ("sqlsrv:server=$hostname;database=$dbname",$username,$pw,[PDO::SQLSRV_TXN_READ_UNCOMMITTED]);
This results in a PDOException: "The auto-commit mode cannot be changed for this driver"
When you're using PDO, you have to use this form:
$conn = new PDO("sqlsrv:Server=".$hostname.
";Database=".$database.
";TransactionIsolation=".PDO::SQLSRV_TXN_READ_UNCOMMITTED,
$username, $pw);
https://msdn.microsoft.com/en-us/library/ff628167.aspx
i'm in trouble. I'm trying to connect remote mysql server with pdo (php 5.4.12). With this code it's connect normally:
$dbh=new PDO('mysql:host=xxx.xxx.xxx.xxx;dbname=newdb', $user, $pass);
But, if i try set host with variable, like this:
$host='xxx.xxx.xxx.xxx';
$dbh=new PDO('mysql:host='.$host.';dbname=newdb', $user, $pass);
It's just thinks sometime, and tell me:
Fatal error: Uncaught exception 'PDOException' with message ' in
D:\wamp\www\test.php on line 21
21 it's line of creating new PDO object.
Ok, i'm try to catch exception (sorry, it's new for me), and now i have this:
Error!: SQLSTATE[HY000] [2002]
Can you help me, please?
Double quoting not helps
$dbh = new PDO("mysql:host=$host;dbname=newdb", $user, $pass);
Nothing changed.
var_dump('mysql:host='.$host.';dbname=newdb');
string 'mysql:host=xx.xx.xxx.xxx;dbname=newdb' (length=37)
Way with {} not helped for me.
Ok, the situation becomes clear. I'm try to connect another server on another IP, and it's normally connected. Can it be mysql server security options?
Try this way
$host = "xxx.xxx.xxx.xxx";
$dbh = new PDO("mysql:host={$host};dbname=newdb", $user, $pass);
The double quotes and the braces to include the var in the string as you can see here
http://www.php.net/manual/en/language.operators.string.php
I have host, database name, username and the password given as form inputs like:
$form['dbname']->getData()
I need to check if these data is correct for the mysql connection. So I chose to use mysql_connect() to check this:
$conn = mysql_connect($form['host']->getData(), $form['username']->getData(), $form['password']->getData(), $form['dbname']->getData());
if($conn) // ...
else // ...
But it displays some mysql_connect() warning with no other specific message...
What's wrong? Does the symfony 2 has any mechanism to check the connection?
Symfony uses repositories and entities to manage the database. The programmer doesn't manipulate the connection itself (Doctrine).
You could try to check a connection using PDO. Try to instance a PDO Object, and catch exceptions (PDOException for connection errors). However, you're "breaking" the framework's philosophy, trying to initiate an "extern" DB connection. If you need to work with several connections in Symfony, I suggest this reference :
http://symfony.com/doc/current/cookbook/doctrine/multiple_entity_managers.html
use the following format to receive the connection error if there is any.
$con = mysql_query() or die(mysql_error());
I'm new at mongoDB and am trying to connect using php driver..
this is my code :
$this->connection = new Mongo("mongodb://tatao_user:tatao_pass#ds043047.mongolab.com:43047/tatao");
but it didn't work and resulting in the error below :
Fatal error: Uncaught exception 'MongoConnectionException' with message 'Couldn't authenticate with database tatao: username [tatao_user]'
I've also tried using the shell, but the reuslt is the same.
please help....
Thx B4...
First of all you need to check if mongodb is running and you have no errors.
Then if you are sure your credential (user and password) are right try this:
<?php
$mongo = new Mongo();
$db = $mongo->db_name; //replace db_name with your db name obviously
$username = "myuser";
$password = "mypassword";
$db->authenticate($username, $password);
?>
you should also check the manual:
http://php.net/manual/en/mongo.connecting.php
Then, i use Codeigniter too, and there is a really good library for mongodb, simple and fast, using Active Records and all the staffs as for the standard database library of CI.
I really suggest you to use that, you can check that here:
https://github.com/alexbilbie/codeigniter-mongodb-library