Solved

PHP ODBC_Exec not working

Posted on 2008-10-27
11
1,137 Views
Last Modified: 2013-12-13
Hi,
For some odd reason odbc_exec returns false for me.
The odbc connection is stablished in my windows server using "microsoft access driver"

Please check the attached code snippet

Thanks,
Ross

$db_con=odbc_connect('mbdmdb','','');
 
if (!$db_con)
  {exit("Connection Failed: ");}
// when i echo the value of $db_con I get a resource id #1 which i believe it means the connection is  
// established
 
	$SQL_FROM = 'tblRequestor';
	$SQL_WHERE = 'FNAME';
 
?>
<?php
	$searchq		=	strip_tags($_GET['q']);
	$getRecord_sql	=	'SELECT * FROM '.$SQL_FROM.' WHERE '.$SQL_WHERE.' like "*'.$searchq.'*"';
	
// $getRecord_sql = SELECT * FROM tblRequestor WHERE FNAME like "*an*". I tried this directly in 
// my access and it returned results 
 
$mgetRecord=odbc_exec($db_con ,.$getRecord_sql);
 
	if ($mgetRecord){
		echo "true";
	}else {
		echo "false";
	}	
// I wonder why I get false here !!!!!!!!

Open in new window

0
Comment
Question by:ucsdmbdm
  • 6
  • 5
11 Comments
 
LVL 82

Expert Comment

by:hielo
ID: 22817935
>>$mgetRecord=odbc_exec($db_con ,.$getRecord_sql);

get rid of the dot infront of $getRecord:
$mgetRecord=odbc_exec($db_con ,$getRecord_sql);
0
 
LVL 82

Expert Comment

by:hielo
ID: 22817939
If the problem persists, try changin the * to % in the LIKE clause.
0
 

Author Comment

by:ucsdmbdm
ID: 22818003
Hi,
Thanks for the reply,
I actually left the dot by mistake in one of my trials. I tried adding double quote to the end and beginning and that didn't work. I also tried using the % instead of * and had no luck. I think this doesn't have to do with the query cause I tried simpler queries and that returned nothing !!!!


0
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
LVL 82

Expert Comment

by:hielo
ID: 22818119
what about:
	if (!$mgetRecord->EOF){
		echo "true";
	}else {
		echo "false";
	}	

Open in new window

0
 

Author Comment

by:ucsdmbdm
ID: 22818208
Hi,
That actually gives me a true,
Can you explain how ->Enf of Line is different from what I was using

Thanks,
Faraz

0
 
LVL 82

Expert Comment

by:hielo
ID: 22818771
I don't know what resource id you are getting for $mgetRecord but the EOF property is set to true when there are NO more records. Since you are negating the whole expression, it executes the if part.
0
 

Author Comment

by:ucsdmbdm
ID: 22818874
Hi,
When I print out the $db_con, I get Resource id #1
However, when I try odbc_num_rows($mgetRecord), I get nothing !

Thanks for the follow up
0
 
LVL 82

Expert Comment

by:hielo
ID: 22818910
I don't know why that might be. Perhaps this will help:
http://us2.php.net/manual/en/function.odbc-exec.php#53126
0
 
LVL 82

Accepted Solution

by:
hielo earned 500 total points
ID: 22818919
0
 

Author Comment

by:ucsdmbdm
ID: 22818936
Thank You,
I am trying them right now.
There are two types of access db plugins in odbc. I might be using the wrong one.
I'll let you know in 15 mins.

Thanks again,

0
 

Author Comment

by:ucsdmbdm
ID: 22819483
The problem turned out to be way trickier than what I thought.
It had to do with my database itself. It was not compatible with the ODBC version I was using.

Thanks
0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Access 2016 - Labels prompt to print 4 32
Access 2016 7 35
Search for text in a .txt file 14 45
Report with several filters - Issue with query? 3 23
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
This article discusses four methods for overlaying images in a container on a web page
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question