MS Access and PHP connection

Asked

Viewed 2,182 times

0

I have a problem making a connection with MS Access and PHP, giving an error that I do not know how to fix, someone could help me ???

The code is this:

//Abre a conexão asdasda
$conn = new COM('ADODB.Connection') or die('ADO não iniciado');
//linha 30 

   $conn->Open('Provider=Microsoft.Jet.OLEDB.4.0; 
   Data Source='.realpath('..\db\dashboard.accdb').'; 
   Persist Security Info=False;');

//fim da linha 30

//Pronto para utilizar o banco de dados

// Fecha a conexão
$conn->Close();

and the mistake is this:

inserir a descrição da imagem aqui

  • Line 30 is the part of the entire $Conn->Open?

  • If yes try to change the part of realpath('.. db Dashboard.accdb') to a variable and concatenate the variable in the string to see what the result is here

  • I already managed to connect to the bank, not directly to it, I linked Access to a msql database and I took the data through this database, I needed the data urgently and I ended up doing this way, but I will test by the way you spoke and put the result here as soon as you give a time, vlw ai :)

  • managed to connect, but changing the code, I’ll put it here because if someone also is having difficulty in this already gives a help

  • For accdb, if I’m not mistaken, you should install version 12 of MS JET. I’ve had a problem with PHP.

1 answer

1


One solution is to use PDO, an example:

// Add arquivo e a extensão 
$database_name = $_SERVER["DOCUMENT_ROOT"] . "C:\..\..\..\..\arquivo.accbd"; 
// Check if file exist.
if (!file_exists($database_name )) {
    die("Não foi possível encontrar o arquivo.");
}
// Conecta o banco com o seu projeto.
$db = new PDO("odbc:DRIVER={Microsoft Access Driver (*.mdb, *.accdb)}; DBNAME=$database_name ; username=; password=;");

try {
     $db = new PDO("odbc:DRIVER={Microsoft Access Driver (*.mdb, *.accbd)}; 
     DBNAME=$database_name ; username=; password=;");

     $db ->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
     echo "Sucesso"; 
}
catch(PDOException $e){
      echo "Falha na Conexão: " . $e->getMessage();
}
  • This is the solution?

  • for my mistake there was, I managed to connect in a good with that code

  • It’s just that I couldn’t figure out if it was a solution or if you posted another code with a problem. I recommend that in future detail whenever possible the answer, speaking the technologies that used, in case used the API called PDO. Ready edited your reply and left an upvote +1

  • is that I had commented up there that I would post the code, but thanks for the tip

  • So, is that the comment fields are disposable, the legal is even detail the minimum that can the answer, indicating for example links to documentation. ;)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.