Dumbfounded
am 22.02.2006 23:31:43 von Sheldon Glickler
I have a script, testsql.php that I run and it works well.
Here are the guts:
session_start();
require_once("sqlLoginDB.php");
mssql_select_db($database_apbLogin, $apbLogin);
$_SESSION['curSpeaker'] = '1000129';
query = "SELECT * FROM speakers WHERE iOldSpeakerId='" .
$_SESSION['curSpeaker'] . "'";
$result = mssql_query($query, $apbLogin);// or die(mssql_error());
echo "Result: " . $result;
It gives me a resource ID number.
When I call a function from another function from the a main page, and this
script is cut and pasted in, the result comes up empty.
I am at a total loss here.
Shelly
Re: Dumbfounded
am 22.02.2006 23:52:52 von Justin Koivisto
Sheldon Glickler wrote:
> I have a script, testsql.php that I run and it works well.
>
> Here are the guts:
>
> session_start();
> require_once("sqlLoginDB.php");
If this is going into a function or included file, it should be an
absolute path. For instance, if the sqlLoginDB.php file is lcoated in
the same directory where this code is found, you should use:
require_once dirname(__FILE__).'/sqlLoginDB.php';
That way, no matter what the current working directory is, the file can
be found.
> mssql_select_db($database_apbLogin, $apbLogin);
No mssql_connect? IF you paste this into a function, you will need to be
sure that you are referencing your db connection either through $GLOBAL
or explicitly define it as global in the function. You should also check
to see that the call succeeded by checking it's return value.
> $_SESSION['curSpeaker'] = '1000129';
> query = "SELECT * FROM speakers WHERE iOldSpeakerId='" .
> $_SESSION['curSpeaker'] . "'";
> $result = mssql_query($query, $apbLogin);// or die(mssql_error());
> echo "Result: " . $result;
You may want to try something like:
if(!is_resource($result)){
// there was a query error of some sort
return mssql_error();
}else{
// the query was a success
}
--
Justin Koivisto, ZCE - justin@koivi.com
http://koivi.com
Re: Dumbfounded
am 22.02.2006 23:52:52 von Justin Koivisto
Sheldon Glickler wrote:
> I have a script, testsql.php that I run and it works well.
>
> Here are the guts:
>
> session_start();
> require_once("sqlLoginDB.php");
If this is going into a function or included file, it should be an
absolute path. For instance, if the sqlLoginDB.php file is lcoated in
the same directory where this code is found, you should use:
require_once dirname(__FILE__).'/sqlLoginDB.php';
That way, no matter what the current working directory is, the file can
be found.
> mssql_select_db($database_apbLogin, $apbLogin);
No mssql_connect? IF you paste this into a function, you will need to be
sure that you are referencing your db connection either through $GLOBAL
or explicitly define it as global in the function. You should also check
to see that the call succeeded by checking it's return value.
> $_SESSION['curSpeaker'] = '1000129';
> query = "SELECT * FROM speakers WHERE iOldSpeakerId='" .
> $_SESSION['curSpeaker'] . "'";
> $result = mssql_query($query, $apbLogin);// or die(mssql_error());
> echo "Result: " . $result;
You may want to try something like:
if(!is_resource($result)){
// there was a query error of some sort
return mssql_error();
}else{
// the query was a success
}
--
Justin Koivisto, ZCE - justin@koivi.com
http://koivi.com
Re: Dumbfounded
am 23.02.2006 00:06:42 von zeldorblat
Justin Koivisto wrote:
> Sheldon Glickler wrote:
> > I have a script, testsql.php that I run and it works well.
> >
> > Here are the guts:
> >
> > session_start();
> > require_once("sqlLoginDB.php");
>
> If this is going into a function or included file, it should be an
> absolute path. For instance, if the sqlLoginDB.php file is lcoated in
> the same directory where this code is found, you should use:
>
> require_once dirname(__FILE__).'/sqlLoginDB.php';
>
> That way, no matter what the current working directory is, the file can
> be found.
Absolutely not. This would imply that sqlLoginDB.php lives in the same
(internet-accessible) directory as the calling file. Files that you
include (database connection code, class definitions, etc.) should live
in a directory /outside/ the webserver document tree. Set the include
path directive in php.ini appropriately.
>
> > mssql_select_db($database_apbLogin, $apbLogin);
>
> No mssql_connect? IF you paste this into a function, you will need to be
> sure that you are referencing your db connection either through $GLOBAL
> or explicitly define it as global in the function. You should also check
> to see that the call succeeded by checking it's return value.
So I'm guessing that you call mssql_connect() inside sqlLoginDB.php.
What exactly are you pasting into your function? All of the code you
pasted above (including the session stuff) ? Be careful that you
aren't calling session_start() more than once or you might have some
weird problems.
>
> > $_SESSION['curSpeaker'] = '1000129';
> > query = "SELECT * FROM speakers WHERE iOldSpeakerId='" .
> > $_SESSION['curSpeaker'] . "'";
> > $result = mssql_query($query, $apbLogin);// or die(mssql_error());
> > echo "Result: " . $result;
>
> You may want to try something like:
>
> if(!is_resource($result)){
> // there was a query error of some sort
> return mssql_error();
> }else{
> // the query was a success
> }
>
> --
> Justin Koivisto, ZCE - justin@koivi.com
> http://koivi.com
Post what you have inside sqlLoginDB.php as well as the entire function
you have created so we have a better idea of what might be going on.
Re: Dumbfounded
am 23.02.2006 00:06:42 von zeldorblat
Justin Koivisto wrote:
> Sheldon Glickler wrote:
> > I have a script, testsql.php that I run and it works well.
> >
> > Here are the guts:
> >
> > session_start();
> > require_once("sqlLoginDB.php");
>
> If this is going into a function or included file, it should be an
> absolute path. For instance, if the sqlLoginDB.php file is lcoated in
> the same directory where this code is found, you should use:
>
> require_once dirname(__FILE__).'/sqlLoginDB.php';
>
> That way, no matter what the current working directory is, the file can
> be found.
Absolutely not. This would imply that sqlLoginDB.php lives in the same
(internet-accessible) directory as the calling file. Files that you
include (database connection code, class definitions, etc.) should live
in a directory /outside/ the webserver document tree. Set the include
path directive in php.ini appropriately.
>
> > mssql_select_db($database_apbLogin, $apbLogin);
>
> No mssql_connect? IF you paste this into a function, you will need to be
> sure that you are referencing your db connection either through $GLOBAL
> or explicitly define it as global in the function. You should also check
> to see that the call succeeded by checking it's return value.
So I'm guessing that you call mssql_connect() inside sqlLoginDB.php.
What exactly are you pasting into your function? All of the code you
pasted above (including the session stuff) ? Be careful that you
aren't calling session_start() more than once or you might have some
weird problems.
>
> > $_SESSION['curSpeaker'] = '1000129';
> > query = "SELECT * FROM speakers WHERE iOldSpeakerId='" .
> > $_SESSION['curSpeaker'] . "'";
> > $result = mssql_query($query, $apbLogin);// or die(mssql_error());
> > echo "Result: " . $result;
>
> You may want to try something like:
>
> if(!is_resource($result)){
> // there was a query error of some sort
> return mssql_error();
> }else{
> // the query was a success
> }
>
> --
> Justin Koivisto, ZCE - justin@koivi.com
> http://koivi.com
Post what you have inside sqlLoginDB.php as well as the entire function
you have created so we have a better idea of what might be going on.
Re: Dumbfounded
am 23.02.2006 01:52:11 von Norman Peelman
"Sheldon Glickler" wrote in message
news:sA5Lf.2064$u%.579@bignews1.bellsouth.net...
> I have a script, testsql.php that I run and it works well.
>
> Here are the guts:
>
> session_start();
> require_once("sqlLoginDB.php");
> mssql_select_db($database_apbLogin, $apbLogin);
> $_SESSION['curSpeaker'] = '1000129';
> query = "SELECT * FROM speakers WHERE iOldSpeakerId='" .
> $_SESSION['curSpeaker'] . "'";
> $result = mssql_query($query, $apbLogin);// or die(mssql_error());
> echo "Result: " . $result;
>
> It gives me a resource ID number.
>
> When I call a function from another function from the a main page, and
this
> script is cut and pasted in, the result comes up empty.
>
> I am at a total loss here.
>
> Shelly
>
>
It's giving you a resource id because that's all your asking it for... you
also need something like:
if ($result)
{
while ($my_resource_data = mssql_fetch_array($result,MSSQL_ASSOC))
{
$my_data[] = $my_resource_data;
}
}
.... you can replace the code located inside the while{} to anything you
like. My code simply dumps the entire result set into an associative array
Norm
Re: Dumbfounded
am 23.02.2006 01:52:11 von Norman Peelman
"Sheldon Glickler" wrote in message
news:sA5Lf.2064$u%.579@bignews1.bellsouth.net...
> I have a script, testsql.php that I run and it works well.
>
> Here are the guts:
>
> session_start();
> require_once("sqlLoginDB.php");
> mssql_select_db($database_apbLogin, $apbLogin);
> $_SESSION['curSpeaker'] = '1000129';
> query = "SELECT * FROM speakers WHERE iOldSpeakerId='" .
> $_SESSION['curSpeaker'] . "'";
> $result = mssql_query($query, $apbLogin);// or die(mssql_error());
> echo "Result: " . $result;
>
> It gives me a resource ID number.
>
> When I call a function from another function from the a main page, and
this
> script is cut and pasted in, the result comes up empty.
>
> I am at a total loss here.
>
> Shelly
>
>
It's giving you a resource id because that's all your asking it for... you
also need something like:
if ($result)
{
while ($my_resource_data = mssql_fetch_array($result,MSSQL_ASSOC))
{
$my_data[] = $my_resource_data;
}
}
.... you can replace the code located inside the while{} to anything you
like. My code simply dumps the entire result set into an associative array
Norm
Re: Dumbfounded
am 23.02.2006 03:02:34 von Sheldon Glickler
"Norman Peelman" wrote in message
news:%G7Lf.10537$_c.569@tornado.tampabay.rr.com...
> "Sheldon Glickler" wrote in message
> news:sA5Lf.2064$u%.579@bignews1.bellsouth.net...
>> I have a script, testsql.php that I run and it works well.
>>
>> Here are the guts:
>>
>> session_start();
>> require_once("sqlLoginDB.php");
>> mssql_select_db($database_apbLogin, $apbLogin);
>> $_SESSION['curSpeaker'] = '1000129';
>> query = "SELECT * FROM speakers WHERE iOldSpeakerId='" .
>> $_SESSION['curSpeaker'] . "'";
>> $result = mssql_query($query, $apbLogin);// or die(mssql_error());
>> echo "Result: " . $result;
>>
>> It gives me a resource ID number.
>>
>> When I call a function from another function from the a main page, and
> this
>> script is cut and pasted in, the result comes up empty.
>>
>> I am at a total loss here.
>>
>> Shelly
>>
>>
>
> It's giving you a resource id because that's all your asking it for...
> you
> also need something like:
>
No, I have the more following this bit where I do an mssql_fetch_assoc on
the result. I just posted to the point of where the problem was.
Shelly
Re: Dumbfounded
am 23.02.2006 03:02:34 von Sheldon Glickler
"Norman Peelman" wrote in message
news:%G7Lf.10537$_c.569@tornado.tampabay.rr.com...
> "Sheldon Glickler" wrote in message
> news:sA5Lf.2064$u%.579@bignews1.bellsouth.net...
>> I have a script, testsql.php that I run and it works well.
>>
>> Here are the guts:
>>
>> session_start();
>> require_once("sqlLoginDB.php");
>> mssql_select_db($database_apbLogin, $apbLogin);
>> $_SESSION['curSpeaker'] = '1000129';
>> query = "SELECT * FROM speakers WHERE iOldSpeakerId='" .
>> $_SESSION['curSpeaker'] . "'";
>> $result = mssql_query($query, $apbLogin);// or die(mssql_error());
>> echo "Result: " . $result;
>>
>> It gives me a resource ID number.
>>
>> When I call a function from another function from the a main page, and
> this
>> script is cut and pasted in, the result comes up empty.
>>
>> I am at a total loss here.
>>
>> Shelly
>>
>>
>
> It's giving you a resource id because that's all your asking it for...
> you
> also need something like:
>
No, I have the more following this bit where I do an mssql_fetch_assoc on
the result. I just posted to the point of where the problem was.
Shelly
Re: Dumbfounded
am 23.02.2006 03:11:19 von Sheldon Glickler
I want to think all who contributed to helping me. the problem is solved.
Here is what I **think** the problem was. I was using the require_once()
for the sqlLoginDB.php. Now, that should have appeared in both the main
module and in the module that holds the functions --at least that is what I
thought.
What I did was to add an assignment to a session variable for the resource
created by the mssql_connect(...) in the sqlLoginDB (and for good measure
threw in a @session_start() at the top of it. I then used that variable
in the function and all worked well.
Thank you all once again. Hopefully I can gain enough experience overtimeto
help others more than they help me.
Shelly
Re: Dumbfounded
am 23.02.2006 03:11:19 von Sheldon Glickler
I want to think all who contributed to helping me. the problem is solved.
Here is what I **think** the problem was. I was using the require_once()
for the sqlLoginDB.php. Now, that should have appeared in both the main
module and in the module that holds the functions --at least that is what I
thought.
What I did was to add an assignment to a session variable for the resource
created by the mssql_connect(...) in the sqlLoginDB (and for good measure
threw in a @session_start() at the top of it. I then used that variable
in the function and all worked well.
Thank you all once again. Hopefully I can gain enough experience overtimeto
help others more than they help me.
Shelly
Re: Dumbfounded
am 23.02.2006 04:38:33 von Justin Koivisto
ZeldorBlat wrote:
> Justin Koivisto wrote:
>> Sheldon Glickler wrote:
>>>
>>> require_once("sqlLoginDB.php");
>>
>> If this is going into a function or included file, it should be an
>> absolute path. For instance, if the sqlLoginDB.php file is lcoated in
>> the same directory where this code is found, you should use:
>>
>> require_once dirname(__FILE__).'/sqlLoginDB.php';
>>
>> That way, no matter what the current working directory is, the file can
>> be found.
>
> Absolutely not. This would imply that sqlLoginDB.php lives in the same
> (internet-accessible) directory as the calling file. Files that you
> include (database connection code, class definitions, etc.) should live
> in a directory /outside/ the webserver document tree. Set the include
> path directive in php.ini appropriately.
I think you missed the point of my statemnet. I didn't say do save it
there... I said *if* it was saved there... The point I was making is
that you want to use absolute system paths, not relative.
I've learned that when giving suggestions to solve a problem to focus on
the specific need at hand. If the OP was asking about a secure or safer
way of doing things, the reply would have been much different.
--
Justin Koivisto, ZCE - justin@koivi.com
http://koivi.com/
*** Free account sponsored by SecureIX.com ***
*** Encrypt your Internet usage with a free VPN account from http://www.SecureIX.com ***
Re: Dumbfounded
am 23.02.2006 04:38:33 von Justin Koivisto
ZeldorBlat wrote:
> Justin Koivisto wrote:
>> Sheldon Glickler wrote:
>>>
>>> require_once("sqlLoginDB.php");
>>
>> If this is going into a function or included file, it should be an
>> absolute path. For instance, if the sqlLoginDB.php file is lcoated in
>> the same directory where this code is found, you should use:
>>
>> require_once dirname(__FILE__).'/sqlLoginDB.php';
>>
>> That way, no matter what the current working directory is, the file can
>> be found.
>
> Absolutely not. This would imply that sqlLoginDB.php lives in the same
> (internet-accessible) directory as the calling file. Files that you
> include (database connection code, class definitions, etc.) should live
> in a directory /outside/ the webserver document tree. Set the include
> path directive in php.ini appropriately.
I think you missed the point of my statemnet. I didn't say do save it
there... I said *if* it was saved there... The point I was making is
that you want to use absolute system paths, not relative.
I've learned that when giving suggestions to solve a problem to focus on
the specific need at hand. If the OP was asking about a secure or safer
way of doing things, the reply would have been much different.
--
Justin Koivisto, ZCE - justin@koivi.com
http://koivi.com/
*** Free account sponsored by SecureIX.com ***
*** Encrypt your Internet usage with a free VPN account from http://www.SecureIX.com ***
Re: Dumbfounded
am 23.02.2006 15:23:33 von D
"Justin Koivisto" wrote in message
news:43fd2f26$0$15443$6d36acad@titian.nntpserver.com...
> ZeldorBlat wrote:
>> Justin Koivisto wrote:
>>> Sheldon Glickler wrote:
>>>>
>>>> require_once("sqlLoginDB.php");
> >>
>>> If this is going into a function or included file, it should be an
>>> absolute path. For instance, if the sqlLoginDB.php file is lcoated in
>>> the same directory where this code is found, you should use:
>>>
>>> require_once dirname(__FILE__).'/sqlLoginDB.php';
>>>
>>> That way, no matter what the current working directory is, the file can
>>> be found.
>>
>> Absolutely not. This would imply that sqlLoginDB.php lives in the same
>> (internet-accessible) directory as the calling file. Files that you
>> include (database connection code, class definitions, etc.) should live
>> in a directory /outside/ the webserver document tree. Set the include
>> path directive in php.ini appropriately.
>
> I think you missed the point of my statemnet. I didn't say do save it
> there... I said *if* it was saved there... The point I was making is that
> you want to use absolute system paths, not relative.
There are perfectly good reasons for using relative paths as opposed to
absolute... :)
> I've learned that when giving suggestions to solve a problem to focus on
> the specific need at hand. If the OP was asking about a secure or safer
> way of doing things, the reply would have been much different.
>
> --
> Justin Koivisto, ZCE - justin@koivi.com
> http://koivi.com/
> *** Free account sponsored by SecureIX.com ***
> *** Encrypt your Internet usage with a free VPN account from
> http://www.SecureIX.com ***
Re: Dumbfounded
am 23.02.2006 15:23:33 von D
"Justin Koivisto" wrote in message
news:43fd2f26$0$15443$6d36acad@titian.nntpserver.com...
> ZeldorBlat wrote:
>> Justin Koivisto wrote:
>>> Sheldon Glickler wrote:
>>>>
>>>> require_once("sqlLoginDB.php");
> >>
>>> If this is going into a function or included file, it should be an
>>> absolute path. For instance, if the sqlLoginDB.php file is lcoated in
>>> the same directory where this code is found, you should use:
>>>
>>> require_once dirname(__FILE__).'/sqlLoginDB.php';
>>>
>>> That way, no matter what the current working directory is, the file can
>>> be found.
>>
>> Absolutely not. This would imply that sqlLoginDB.php lives in the same
>> (internet-accessible) directory as the calling file. Files that you
>> include (database connection code, class definitions, etc.) should live
>> in a directory /outside/ the webserver document tree. Set the include
>> path directive in php.ini appropriately.
>
> I think you missed the point of my statemnet. I didn't say do save it
> there... I said *if* it was saved there... The point I was making is that
> you want to use absolute system paths, not relative.
There are perfectly good reasons for using relative paths as opposed to
absolute... :)
> I've learned that when giving suggestions to solve a problem to focus on
> the specific need at hand. If the OP was asking about a secure or safer
> way of doing things, the reply would have been much different.
>
> --
> Justin Koivisto, ZCE - justin@koivi.com
> http://koivi.com/
> *** Free account sponsored by SecureIX.com ***
> *** Encrypt your Internet usage with a free VPN account from
> http://www.SecureIX.com ***
Re: Dumbfounded
am 23.02.2006 15:30:15 von Justin Koivisto
d wrote:
> "Justin Koivisto" wrote in message
> news:43fd2f26$0$15443$6d36acad@titian.nntpserver.com...
>> ZeldorBlat wrote:
>>> Justin Koivisto wrote:
>>>> Sheldon Glickler wrote:
>>>>> require_once("sqlLoginDB.php");
>>>> If this is going into a function or included file, it should be an
>>>> absolute path. For instance, if the sqlLoginDB.php file is lcoated in
>>>> the same directory where this code is found, you should use:
>>>>
>>>> require_once dirname(__FILE__).'/sqlLoginDB.php';
>>>>
>>>> That way, no matter what the current working directory is, the file can
>>>> be found.
>>> Absolutely not. This would imply that sqlLoginDB.php lives in the same
>>> (internet-accessible) directory as the calling file. Files that you
>>> include (database connection code, class definitions, etc.) should live
>>> in a directory /outside/ the webserver document tree. Set the include
>>> path directive in php.ini appropriately.
>> I think you missed the point of my statemnet. I didn't say do save it
>> there... I said *if* it was saved there... The point I was making is that
>> you want to use absolute system paths, not relative.
>
> There are perfectly good reasons for using relative paths as opposed to
> absolute... :)
The way I usually handle it is to set the include_path and then use
relative paths. However, when I am not doing that, I like to use things
like:
dirname(__FILE__).'/../../../inc_dir/file.php';
that way it is an absolute path according to the execution, but still
relative in relation to the script. (If that makes any sense!)
--
Justin Koivisto, ZCE - justin@koivi.com
http://koivi.com
Re: Dumbfounded
am 23.02.2006 15:30:15 von Justin Koivisto
d wrote:
> "Justin Koivisto" wrote in message
> news:43fd2f26$0$15443$6d36acad@titian.nntpserver.com...
>> ZeldorBlat wrote:
>>> Justin Koivisto wrote:
>>>> Sheldon Glickler wrote:
>>>>> require_once("sqlLoginDB.php");
>>>> If this is going into a function or included file, it should be an
>>>> absolute path. For instance, if the sqlLoginDB.php file is lcoated in
>>>> the same directory where this code is found, you should use:
>>>>
>>>> require_once dirname(__FILE__).'/sqlLoginDB.php';
>>>>
>>>> That way, no matter what the current working directory is, the file can
>>>> be found.
>>> Absolutely not. This would imply that sqlLoginDB.php lives in the same
>>> (internet-accessible) directory as the calling file. Files that you
>>> include (database connection code, class definitions, etc.) should live
>>> in a directory /outside/ the webserver document tree. Set the include
>>> path directive in php.ini appropriately.
>> I think you missed the point of my statemnet. I didn't say do save it
>> there... I said *if* it was saved there... The point I was making is that
>> you want to use absolute system paths, not relative.
>
> There are perfectly good reasons for using relative paths as opposed to
> absolute... :)
The way I usually handle it is to set the include_path and then use
relative paths. However, when I am not doing that, I like to use things
like:
dirname(__FILE__).'/../../../inc_dir/file.php';
that way it is an absolute path according to the execution, but still
relative in relation to the script. (If that makes any sense!)
--
Justin Koivisto, ZCE - justin@koivi.com
http://koivi.com