For Programmers: Free Programming Magazines  


Home > Archive > PHP Pear > September 2005 > DB Newbie question.









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author DB Newbie question.
LinuXKiD

2005-09-22, 6:57 pm


I've:
Windows XP +
Apache 1.3.28 +
PHP 4.3.3 +
PEAR +
MS Access 2000 +
MDAC 2.8
PC

All working perfectly, but when I try to connect
to ACCESS throug DB PEAR, I get an error:

Standard Message: DB Error: connect failed Standard Code: -24 DBMS/User
Message: [nativecode=IM002 [Microsoft][ODBC Driver Manager] Data source name
not found and no default driver specified] ** Array DBMS/Debug Message:
[nativecode=IM002 [Microsoft][ODBC Driver Manager] Data source name not
found and no default driver specified] ** Array

BUT, when I not use PEAR DB , works!

This can't connect:

<?php

// PEAR DB VERSION

error_reporting(E_ALL);

require_once 'DB.php';

$dsn=array(
'phptype' => 'odbc',
'dbsyntax' => 'access',
// 'protocol' => false,
'hostspec' => '127.0.0.1',
'database' => 'TestDB',
'username' => '',
'password' => ''
// 'proto_opts' => false,
// 'option' =>false
);

$options = array(
'debug' => 5
);


$db =& DB::connect($dsn, $options);
if (PEAR::isError($db)) {
echo 'Standard Message: ' . $db->getMessage() . "\n";
echo 'Standard Code: ' . $db->getCode() . "\n";
echo 'DBMS/User Message: ' . $db->getUserInfo() . "\n";
echo 'DBMS/Debug Message: ' . $db->getDebugInfo() . "\n";
exit;
}

die("ok");

?>


how ever this non PEAR script WORKS !! ( script from phpfreaks tutorial)

<?php

error_reporting(E_ALL);

$odbc = odbc_connect ('TestDB', '', '') or die('Could Not Connect to ODBC
Database!');

if(!function_exists('odbc_fetch_array'))

{
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 = odbc_exec($odbc, "SELECT * FROM Tabla1") or die (odbc_errormsg());

while($row = odbc_fetch_array($query))
{
echo 'ID: '.$row['id'].'<br />';
echo 'Nombre: '.$row['nombre'].'<br />';
echo 'Apellido: '.$row['apellido'].'<br />';
echo '<hr />';
}
odbc_close($odbc);

?>

Anybody can help me ?
I want to run a PEAR DB powered script.

Thank you in advance.

andres.
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com