Solved

PHP ODBC_Exec not working

Posted on 2008-10-27
11
1,128 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
 
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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
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.
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 …

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now