...

View Full Version : odbc connect script for mysql



steviecee
06-17-2005, 04:21 PM
i have a php odbc connect script for a ms access database as shown below

<?
$odbc = odbc_connect ('DIT_test.mdb', '', '') 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;
}
?>

would this have to be changed to run a mysql database instread of the access one? i've tried using this for a mysql database with no luck, what would i need to change (apart from the database name!) if anything?
cheers
steve

Kid Charming
06-17-2005, 05:11 PM
PHP has a separate set of functions for different database types. The logic should be more or less the same, but you need to replace all your odbc functions with MySQL functions (http://us2.php.net/manual/en/ref.mysql.php). The 'important' ones are mysql_connect(), mysql_select_db(), mysql_query(), and the various mysql_fetch_ functions.

devinemke
06-17-2005, 05:32 PM
or use PHP's database abstraction layer (http://www.php.net/manual/en/ref.dbx.php).

steviecee
06-20-2005, 02:38 PM
thqanks for those replies, problem solved :thumbsup:
steve



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum