 |

07-06-2004, 10:30 PM
|
|
Newcomer
|
|
Join Date: May 2004
Location: Texas
Posts: 20
|
|
PHP Data Access
|
I am trying to use ODBC to access a MS Access Database and keep getting this error when I try to run it, I am also running Apache and trying to use php code.
Warning: odbc_connect(): SQL error: [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified, SQL state IM002 in SQLConnect in C:\Program Files\Apache Group\Apache2\htdocs\Access\source\odbc.php on line 3
odbc.php file
PHP Code:
<?
$odbc = odbc_connect ('Test', 'root', '') or die( "Could Not Connect to ODBC Database!");
if (function_exists(odbc_fetch_array))
return;
function odbc_fetch_array($result, $rownumber=-1) {
if (PHP_VERSION > "4.1") {
if ($rownumber < 0) {
odbc_fetch_into($result, $rs);
} else {
odbc_fetch_into($result, $rs, $rownumber);
}
} else {
odbc_fetch_into($result, $rownumber, $rs);
}
$rs_assoc = Array();
foreach ($rs as $key => $value) {
$rs_assoc[odbc_field_name($result, $key+1)] = $value;
}
return $rs_assoc;
}
?>
query.php file
PHP Code:
<?
include 'odbc.php';
$query = odbc_exec($odbc, "SELECT * FROM Customers") or die (odbc_errormsg());
while($row = odbc_fetch_array($query)){
echo "Customer First Name: ".$row['customer_first_name']."<br />";
echo "Customer Last Name: ".$row['customer_last_name']."<br />";
echo "Customer Email: ".$row['email_address']."<br />";
echo "<hr />";
}
odbc_close($odbc);
?>
if anyone could help I would appreciate it thanks 
|
__________________
"People that don't make mistakes are people the don't do anything." Author Unkown
|

07-12-2004, 11:33 AM
|
|
Newcomer
|
|
Join Date: Mar 2004
Posts: 7
|
|
I'm more familiar with using php with mySQL databases, but from what it seems you are not connecting to the database. Are you using phpdev? (just wondering because you have "root" "" as your user/pass)...In connecting to a mySQL database with mysql_connect(), that first param is the server where the database is located. You have it as "Test". I may be wrong, but try changing it to "localhost" to let it know that the database is running on the same server as the script. Just a thought, I'm new at this
- Dan
|
|

07-12-2004, 06:19 PM
|
|
Contributor
|
|
Join Date: Oct 2003
Posts: 747
|
|
|
Well, if what I am reading is the same as what I am thinking, the problem is clear.
You are trying to use the username 'root', and a blank password, which is fine. The problem is that your script is trying to connect to a machine named 'Test', and because it can't find 'Test', it can't connect. Try changing it to localhost, or the address of wherever your DB server is.
|
|

07-13-2004, 08:19 AM
|
 |
Web Junkie
Retired Moderator * Expert *
|
|
Join Date: Apr 2004
Location: D/FW, Texas, USA
Posts: 8,393
|
|
|
Do you have a System (or Machine) DSN created that has a name of 'Test', that points to your database? And are you sure the user name is 'root' with a blank password.
In general, if you open an Access Database with out a user name or password, you are connected as 'Admin' with a blank password.
Just a few things to look at.
|
__________________
-- wayne, MSSM Retired
> SELECT * FROM users WHERE clue > 0
0 rows returned
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|