Jump to content

[SOLVED] MS Access-ODBC, Can't get data


Fahid

Recommended Posts

Hello All,

 

I am trying to get some data from a MS Access database through ODBC, but don't know why I am failing no matter what I try.

my code is given below

I run this code and get the following error/output, which I have set to be displayed if no record is selected

get_given_number-no records found

This means that my query is not affecting/selecting any data/row from the database.

 

Please help WHY?

 

<?php
function get_given_number($num){
$conn = odbc_connect(settings('dsn'), settings('user'), settings('pass')) or die(odbc_error()."Cant conect");
$query = "SELECT * FROM pNum WHERE `iNum`='$num' ORDER BY `iSr` DESC";
//$query = "SELECT * FROM pNum";
$result = odbc_exec($conn, $query) or die(odbc_error($conn) . "get_given_number-query error");
$affected_rows = odbc_num_rows($result);
//die($affected_rows);
if($affected_rows < 1 ) die("get_given_number-no records found");
$output = '';
$entry_list = file_as_var('includes/pdel_entry_list.html');

while(odbc_fetch_row($result)){
	$serial = odbc_result($result, 'iSr');
	$reference = odbc_result($result, 'iRef');
	$party_name = get_party_name($reference);
	$party_status = get_party_status($reference);
	if($party_status == 0) continue;
	$type = odbc_result($result,'iTyp2');
	$amounta = odbc_result($result,'iAmnt');
	$amountb = odbc_result($result,'iAmnt2');
	$output .= format_entry($num, $serial, $party_name, $type, $amounta, $amountb);
}
$output = str_replace('__ENTRIES__',$output,$entry_list);
$output = str_replace('__iNum__',$number,$output);
odbc_close_all();
return $output;	

}
echo get_given_number('7139');
?>

Link to comment
Share on other sites

Thanks a lot Mr. Mchl,

I didn't found this thing in PHP documentation and was really troubled.

Thanks a lot.

 

1 more little question please,

can I delete a row/record from MS Access through PHP/ODBC ?

 

I mean will this work

DELETE FROM pNum WHERE `iRef`= '10' LIMIT 1

Link to comment
Share on other sites

Thanks a lot Mr. Mchl,

I didn't found this thing in PHP documentation and was really troubled.

Thanks a lot.

 

1 more little question please,

can I delete a row/record from MS Access through PHP/ODBC ?

 

I mean will this work

DELETE FROM pNum WHERE `iRef`= '10' LIMIT 1

I tried it myself, and it does delete the record from MS Access DB

 

Thanks a lot again for help.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.