0

Update 1: @Fred -ii- Thanks! That resolved that issue by restarting those services.

Next problem that I'm getting when running in Neatbeans now

Uncaught exception 'PDOException' with message 'SQLSTATE[IM002] SQLDriverConnect: 0 [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

I understand that Access is not the preferred method, but this for a Project so the tools are out of my hands.

To clarify I am running this on Windows 7 x64.

This is what I'm making -

A php login that will see if a user exist in a database already, if not it will add them. For simplicity's sake we're not concerned if someone else already has this user name.

I have no PHP experience, so after finally getting XAMMP and all other required things setup to run PHP through Neatbeans, I'm at a new problem involving PDO and understanding how it works.

    <?php

echo '<pre>';
print_r(PDO::getAvailableDrivers());

if(isset($_REQUEST['attempt']))
{
    $user = $_POST['user'];
    $password = $_POST['password'];
}


//Path to our database
$database_path = "./Users.accdb";

if(!file_exists($database_path))
{
    die("Acess database file not found!");
}


$conn = new PDO("odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};Dbq=".$database_path.";Uid=; Pwd=;");


?>
<form method="post" action="index.php?attempt">
    User <input type="text" name="user" /><br />
    Pass <input type="password" name="password"><br />

    <input type="submit" />
    </form>

Everything worked until I had to actually open a connection to the database. This is the error I'm getting when I run in Netbeans.

"Fatal error:  Uncaught exception 'PDOException' with message 'could not find driver' in C:\xampp\htdocs\Php_Login\index.php:22"

This is the output of my available drivers.

[0] => mysql
[1] => sqlite

Am I missing something? I've read through so many pages and I still can't understand why I don't have the required driver for this. I'm not asking anyone to do my Project for me, just some insight into my current roadblock.

Thanks in advance.

Pelelt12
  • 1
  • 5

1 Answers1

0

are you on a windows machine?

make sure the system has odbc set up.

You can see this link as guide.

You should also checkout this stackoverflow post

And this


Edit:

You also need to make sure that you restarted all services after making changes to system files. Those changes will not take effect until you do.

Edit:

Also ensure you absolute path to the file is used

Community
  • 1
  • 1
yomexzo
  • 665
  • 1
  • 6
  • 22
  • Yes, should have mentioned I am on Windows and ODBC is setup. I've actually read through both of those pages multiple times, I'm fairly certain I won't have any problem getting the queries to work, just getting the database connection open is my primary issue. – Pelelt12 Oct 25 '15 at 21:51
  • @Pelelt12 did you uncomment `extension=php_pdo_odbc.dll` in `php.ini`? if you did. are you sure you're editing the right `php.ini`? To be sure do this ` – yomexzo Oct 25 '15 at 21:54
  • If I understand the ini file properly, removing the ; un-comments it correct? Configuration File (php.ini) Path C:\Windows Did you want any other results from phpinfo? – Pelelt12 Oct 25 '15 at 22:00
  • yes. removing `;` is un-commenting. BUT you need to be sure you're editing the right `php.ini`. A lot of us have fallen into that trap so many times – yomexzo Oct 25 '15 at 22:05
  • @Pelelt12 Make sure you restart all services and especially PHP after making changes to system files. – Funk Forty Niner Oct 25 '15 at 22:09
  • How can I tell if I have edited the correct ini file? – Pelelt12 Oct 25 '15 at 22:11
  • Thanks @ Fred -ii- I updated my post with a new issue I'm having now after your solution fixed the no driver found error. – Pelelt12 Oct 25 '15 at 22:17
  • @Pelelt12 that's great, glad to hear that the issue was solved, *cheers* – Funk Forty Niner Oct 25 '15 at 22:21
  • @Pelelt12 I made an edit to the answer (to reflect the solution) since it didn't make sense for me to add an answer. Consider accepting the answer in order to mark the question as solved, *cheers* – Funk Forty Niner Oct 25 '15 at 22:23
  • @Fred -ii- My mistake, in my haste I misread what I seeing. Still getting the same error of no driver found. – Pelelt12 Oct 25 '15 at 22:25
  • @Pelelt12 have a look at the manual on the driver http://php.net/manual/en/ref.pdo-odbc.connection.php - I'm not entirely that what you're using right now `new PDO("odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)}` is correct. I myself have never worked with MSSQL, I'm an MySQL guy. See this Q&A http://stackoverflow.com/q/15831246/ also and http://stackoverflow.com/q/17164316/ - I hope that helps. – Funk Forty Niner Oct 25 '15 at 22:29
  • @Pelelt12 ... try this `$conn = new PDO("odbc:Driver={Microsoft Access Driver (*.mdb, *.accdb)};Dbq=".realpath($database_path).";Uid=; Pwd=;");` – yomexzo Oct 25 '15 at 22:45
  • @yomexzo That was the problem! I even commented my line to add back the mdb but I glossed over it every time. Thanks so much! The rest is in my hands now. Thanks everyone that contributed. – Pelelt12 Oct 25 '15 at 22:50
  • glad we could help @Pelelt12 .. i have added more info to the answer.. you should mark it as your answer if it surely is .. cheers – yomexzo Oct 26 '15 at 00:09