Solved

PHP ODBC_Exec not working

Posted on 2008-10-27
11
1,156 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

624 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