Solved

PHP ODBC_Exec not working

Posted on 2008-10-27
11
1,151 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
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.  

 
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

[Webinar] Code, Load, and Grow

Managing multiple websites, servers, applications, and security on a daily basis? Join us for a webinar on May 25th to learn how to simplify administration and management of virtual hosts for IT admins, create a secure environment, and deploy code more effectively and frequently.

Question has a verified solution.

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

Suggested Solutions

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
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.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

739 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