OK, I see some similar questions to mine, but their examples all use PHP classes...mine does not. Maybe that's the problem? I shouldn't need classes because my site is exceedingly simple at this point in time.

Anyway, I'm trying to use PDO to connect to a MySQL db. I connect to the db fine in a file called `config.php`, and include this file in `index.php` with `require_once()`.

I can successfully query the db from another file called `process.php`, but the problem is within a function within that file; it seems my DBO object is out of scope within that function.

Here are the relevant code snippets:

**index.php**

```
require_once('./lib/config.php');

```

**config.php**

```
// tested and connects fine    
$pdo = new PDO('mysql:host=' . $hostname . ';dbname=' . $dbname, $username, $password, array(
    PDO::ATTR_PERSISTENT => true
));

```

**process.php**

```
<?php
...
// can call $pdo fine in this file outside of functions
...

function authenticate($u, $p) {
    // can't call $pdo in here, error says $pdo is non-object
    $que = $pdo->query('select user_id, user_pass from users where user_name = \'' . $u . '\' limit 1');
    ...
}

?>

```

By the way, I'm using PDO because I was having similar trouble with `mysqli`, and am trying to get away from `mysql`, which is apparently depreciated and discouraged.

EDIT: I should have clarified first based on the number of responses I got on this matter: I did try to **pass $pdo in as a param to the function**, with no luck or change in the error message.

SOLUTION: OK, apparently the problem was that I needed to add `require_once('config.php')` in my **process.php** file as well. Not sure why (wouldn't it already be included when **index.php** was run first?). Then I was able to successfully pass `$pdo` in as a param to my function, and voila.