Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

PHP ODBC_Exec not working

Posted on 2008-10-27
11
Medium Priority
?
1,186 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 1500 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This article discusses how to implement server side field validation and display customized error messages to the client.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

885 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