/    Sign up×
Community /Pin to ProfileBookmark

php odbc not staying open

Hi everyone,

I have a little problem.

Here is the structure

main.php
main.inc
connections.inc

here is the code

[code=php]
$conn = odbc_connect($database,$user,$password); //connect to database

$queryd=”SELECT distinct DeptName, DeptAbrev, DeptRecordID FROM DeptNames

order by DeptName”;

$resultd=odbc_exec($conn,$queryd);

$numd=odbc_num_rows($resultd);

//———–wont run this one—————
$queryt=”SELECT distinct Title, TitleCode, Dept FROM JobTitle
where TitleCode <> ”

order by Dept, Title”;

$resultt=odbc_exec($conn,$queryt);

$num=odbc_num_rows($resultt);

[/code]

Now if I try to run another Query using the same connection “$conn” it gives me a warning

[code=html]
Warning: odbc_num_rows() expects parameter 1 to be resource

[/code]

so it runs the first query with $conn but none of the others on the same page.

if I re-add the $conn in-front of the 2nd query, it will run.

Any suggestions?

Thank
Nat

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@criterion9Aug 22.2011 — Hi everyone,

I have a little problem.

Here is the structure

main.php

main.inc

connections.inc

here is the code
[code=php]
$conn = odbc_connect($database,$user,$password); //connect to database

$queryd="SELECT distinct DeptName, DeptAbrev, DeptRecordID FROM DeptNames

order by DeptName";

$resultd=odbc_exec($conn,$queryd);

$numd=odbc_num_rows($resultd);


//-----------wont run this one---------------
$queryt="SELECT distinct Title, TitleCode, Dept FROM JobTitle
where TitleCode <> ''

order by Dept, Title";

$resultt=odbc_exec($conn,$queryt);

$num=odbc_num_rows($resultt);

[/code]

Now if I try to run another Query using the same connection "$conn" it gives me a warning

[code=html]
Warning: odbc_num_rows() expects parameter 1 to be resource

[/code]


so it runs the first query with $conn but none of the others on the same page.

if I re-add the $conn in-front of the 2nd query, it will run.

Any suggestions?

Thank

Nat[/QUOTE]


It looks like the connection is still open but you might be getting an error from your second query?
Copy linkTweet thisAlerts:
@NatdripauthorAug 22.2011 — I figured it out turns out that the programmer before was using a

[code=php]
<?
[/code]

instead of this
[code=php]
<?php
[/code]


I was also missing a few tables from the main sql server

which was lame seeing as I used the built in wizard to transfer the

live server.

so I over looked that

But thanks
×

Success!

Help @Natdrip spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...