FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » ODBC Connection
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
ODBC Connection [message #172726] Sun, 27 February 2011 17:57 Go to next message
bruceaj is currently offline  bruceaj
Messages: 30
Registered: September 2010
Karma: 0
Member
I am connecting to an MS Access database. The connection and exec work
fine. My problem is getting the data.

The following two statement work;
$row = odbc_fetch_array($rs);
$value = $row['Newspaper'];

If I change to
$value = $row[1];

is_null($value) returns true.

What am I doing wrong or is an idiosyncrasy of using MS Access?

Bruce
Re: ODBC Connection [message #172727 is a reply to message #172726] Sun, 27 February 2011 18:07 Go to previous messageGo to next message
Luuk is currently offline  Luuk
Messages: 329
Registered: September 2010
Karma: 0
Senior Member
On 27-02-11 18:57, bruceaj wrote:
> I am connecting to an MS Access database. The connection and exec work
> fine. My problem is getting the data.
>
> The following two statement work;
> $row = odbc_fetch_array($rs);
> $value = $row['Newspaper'];
>
> If I change to
> $value = $row[1];
>
> is_null($value) returns true.
>
> What am I doing wrong or is an idiosyncrasy of using MS Access?
>
> Bruce
>

This would probably tell more:
print_r($row);


--
Luuk
Re: ODBC Connection [message #172728 is a reply to message #172727] Sun, 27 February 2011 18:24 Go to previous messageGo to next message
bruceaj is currently offline  bruceaj
Messages: 30
Registered: September 2010
Karma: 0
Member
On Feb 27, 1:07 pm, Luuk <L...@invalid.lan> wrote:
> On 27-02-11 18:57, bruceaj wrote:
>
>
>
>> I am connecting to an MS Access database. The connection and exec work
>> fine. My problem is getting the data.
>
>> The following two statement work;
>> $row = odbc_fetch_array($rs);
>> $value = $row['Newspaper'];
>
>> If I change to
>> $value = $row[1];
>
>> is_null($value) returns true.
>
>> What am I doing wrong or is an idiosyncrasy of using MS Access?
>
>> Bruce
>
> This would probably tell more:
> print_r($row);
>
> --
> Luuk

Okay.. Thanks for the response.

Array ( [Newspaper] => Review [Year] => 1887 [Month] => 5 [Day] => 20
[Page] => 4 [Column] => 3 [Father First] => Joe [Father Middle] =>
[Mother First] => [Mother Middle] => [Mother Maiden] => [First] =>
Daughter [Middle] => [Last] => Allen [Date Of Birth] => 05/18/1887
[Date Of Baptism] => [Church] => [Counter] => 1 [NewspaperKey] => 1
[Comments] => )

Hope this helps..

Thanks again.

Bruce
Re: ODBC Connection [message #172729 is a reply to message #172726] Sun, 27 February 2011 18:36 Go to previous messageGo to next message
richard is currently offline  richard   
Messages: 213
Registered: June 2013
Karma: 0
Senior Member
On Sun, 27 Feb 2011 09:57:11 -0800 (PST), bruceaj wrote:

> I am connecting to an MS Access database. The connection and exec work
> fine. My problem is getting the data.
>
> The following two statement work;
> $row = odbc_fetch_array($rs);
> $value = $row['Newspaper'];
>
> If I change to
> $value = $row[1];
>
> is_null($value) returns true.
>
> What am I doing wrong or is an idiosyncrasy of using MS Access?
>
> Bruce

I'd say it's due to the fact you did not define $row[1].
Instead, you used 'newspaper' as the row identifier.
It can't find [1] so it reports an error.
Re: ODBC Connection [message #172734 is a reply to message #172729] Sun, 27 February 2011 18:49 Go to previous messageGo to next message
bruceaj is currently offline  bruceaj
Messages: 30
Registered: September 2010
Karma: 0
Member
On Feb 27, 1:36 pm, richard <mem...@newsguy.com> wrote:
> On Sun, 27 Feb 2011 09:57:11 -0800 (PST), bruceaj wrote:
>> I am connecting to an MS Access database. The connection and exec work
>> fine. My problem is getting the data.
>
>> The following two statement work;
>> $row = odbc_fetch_array($rs);
>> $value = $row['Newspaper'];
>
>> If I change to
>> $value = $row[1];
>
>> is_null($value) returns true.
>
>> What am I doing wrong or is an idiosyncrasy of using MS Access?
>
>> Bruce
>
> I'd say it's due to the fact you did not define $row[1].
> Instead, you used 'newspaper' as the row identifier.
> It can't find [1] so it reports an error.

Okay??? I guess I don't know what I thought I knew!!

Doesn't "odbc_fetch_array" returns an associative array. If so, can't
I address the elements either by name "newspaper" or by index "1".

One minor point, the index I should be using is "0" since the
associative array is 0 based.

Appreciate some suggestions on what I need to address the elements of
my array, $row, via an index value.

Thanks again...

Bruce
Re: ODBC Connection [message #172735 is a reply to message #172728] Sun, 27 February 2011 18:54 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 2/27/2011 1:24 PM, bruceaj wrote:
> On Feb 27, 1:07 pm, Luuk<L...@invalid.lan> wrote:
>> On 27-02-11 18:57, bruceaj wrote:
>>
>>
>>
>>> I am connecting to an MS Access database. The connection and exec work
>>> fine. My problem is getting the data.
>>
>>> The following two statement work;
>>> $row = odbc_fetch_array($rs);
>>> $value = $row['Newspaper'];
>>
>>> If I change to
>>> $value = $row[1];
>>
>>> is_null($value) returns true.
>>
>>> What am I doing wrong or is an idiosyncrasy of using MS Access?
>>
>>> Bruce
>>
>> This would probably tell more:
>> print_r($row);
>>
>> --
>> Luuk
>
> Okay.. Thanks for the response.
>
> Array ( [Newspaper] => Review [Year] => 1887 [Month] => 5 [Day] => 20
> [Page] => 4 [Column] => 3 [Father First] => Joe [Father Middle] =>
> [Mother First] => [Mother Middle] => [Mother Maiden] => [First] =>
> Daughter [Middle] => [Last] => Allen [Date Of Birth] => 05/18/1887
> [Date Of Baptism] => [Church] => [Counter] => 1 [NewspaperKey] => 1
> [Comments] => )
>
> Hope this helps..
>
> Thanks again.
>
> Bruce

Which is exactly what you should get if you fetch as an associative
array. If you want to access the values by index, you need to fetch
with an indexed array (odbc_fetch_row())/

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: ODBC Connection [message #172736 is a reply to message #172728] Sun, 27 February 2011 19:04 Go to previous messageGo to next message
Luuk is currently offline  Luuk
Messages: 329
Registered: September 2010
Karma: 0
Senior Member
On 27-02-11 19:24, bruceaj wrote:
> On Feb 27, 1:07 pm, Luuk <L...@invalid.lan> wrote:
>> On 27-02-11 18:57, bruceaj wrote:
>>
>>
>>
>>> I am connecting to an MS Access database. The connection and exec work
>>> fine. My problem is getting the data.
>>
>>> The following two statement work;
>>> $row = odbc_fetch_array($rs);
>>> $value = $row['Newspaper'];
>>
>>> If I change to
>>> $value = $row[1];
>>
>>> is_null($value) returns true.
>>
>>> What am I doing wrong or is an idiosyncrasy of using MS Access?
>>
>>> Bruce
>>
>> This would probably tell more:
>> print_r($row);
>>
>> --
>> Luuk
>
> Okay.. Thanks for the response.
>
> Array ( [Newspaper] => Review [Year] => 1887 [Month] => 5 [Day] => 20
> [Page] => 4 [Column] => 3 [Father First] => Joe [Father Middle] =>
> [Mother First] => [Mother Middle] => [Mother Maiden] => [First] =>
> Daughter [Middle] => [Last] => Allen [Date Of Birth] => 05/18/1887
> [Date Of Baptism] => [Church] => [Counter] => 1 [NewspaperKey] => 1
> [Comments] => )
>
> Hope this helps..
>
> Thanks again.
>
> Bruce

http://www.php.net/manual/en/language.types.array.php

--
Luuk
Re: ODBC Connection [message #172739 is a reply to message #172734] Sun, 27 February 2011 19:19 Go to previous messageGo to next message
richard is currently offline  richard   
Messages: 213
Registered: June 2013
Karma: 0
Senior Member
On Sun, 27 Feb 2011 10:49:26 -0800 (PST), bruceaj wrote:

> On Feb 27, 1:36 pm, richard <mem...@newsguy.com> wrote:
>> On Sun, 27 Feb 2011 09:57:11 -0800 (PST), bruceaj wrote:
>>> I am connecting to an MS Access database. The connection and exec work
>>> fine. My problem is getting the data.
>>
>>> The following two statement work;
>>> $row = odbc_fetch_array($rs);
>>> $value = $row['Newspaper'];
>>
>>> If I change to
>>> $value = $row[1];
>>
>>> is_null($value) returns true.
>>
>>> What am I doing wrong or is an idiosyncrasy of using MS Access?
>>
>>> Bruce
>>
>> I'd say it's due to the fact you did not define $row[1].
>> Instead, you used 'newspaper' as the row identifier.
>> It can't find [1] so it reports an error.
>
> Okay??? I guess I don't know what I thought I knew!!
>
> Doesn't "odbc_fetch_array" returns an associative array. If so, can't
> I address the elements either by name "newspaper" or by index "1".
>
> One minor point, the index I should be using is "0" since the
> associative array is 0 based.
>
> Appreciate some suggestions on what I need to address the elements of
> my array, $row, via an index value.
>
> Thanks again...
>
> Bruce

as I understand it, the array contents have to be defined.
If you define an array with names rather than number, then you can not
assume 0 is going to be the first array item. Or that 0 will be associated
with the first item by default.

$item[0]="aaa"
$item[1]="bbb"
$item['sample']="ccc"
$item['data']="data"
$item[2]="ddd"

If I wanted to recall the third item in the array, I would have to use
['sample'] not [2].
If [2] did not exist, I can not assume [2] would equate to ['sample'].

IOW, what you defined in the array, is what can be recalled.
Re: ODBC Connection [message #172743 is a reply to message #172739] Sun, 27 February 2011 19:51 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 2/27/2011 2:19 PM, richard wrote:
> On Sun, 27 Feb 2011 10:49:26 -0800 (PST), bruceaj wrote:
>
>> On Feb 27, 1:36 pm, richard<mem...@newsguy.com> wrote:
>>> On Sun, 27 Feb 2011 09:57:11 -0800 (PST), bruceaj wrote:
>>>> I am connecting to an MS Access database. The connection and exec work
>>>> fine. My problem is getting the data.
>>>
>>>> The following two statement work;
>>>> $row = odbc_fetch_array($rs);
>>>> $value = $row['Newspaper'];
>>>
>>>> If I change to
>>>> $value = $row[1];
>>>
>>>> is_null($value) returns true.
>>>
>>>> What am I doing wrong or is an idiosyncrasy of using MS Access?
>>>
>>>> Bruce
>>>
>>> I'd say it's due to the fact you did not define $row[1].
>>> Instead, you used 'newspaper' as the row identifier.
>>> It can't find [1] so it reports an error.
>>
>> Okay??? I guess I don't know what I thought I knew!!
>>
>> Doesn't "odbc_fetch_array" returns an associative array. If so, can't
>> I address the elements either by name "newspaper" or by index "1".
>>
>> One minor point, the index I should be using is "0" since the
>> associative array is 0 based.
>>
>> Appreciate some suggestions on what I need to address the elements of
>> my array, $row, via an index value.
>>
>> Thanks again...
>>
>> Bruce
>
> as I understand it, the array contents have to be defined.
> If you define an array with names rather than number, then you can not
> assume 0 is going to be the first array item. Or that 0 will be associated
> with the first item by default.
>
> $item[0]="aaa"
> $item[1]="bbb"
> $item['sample']="ccc"
> $item['data']="data"
> $item[2]="ddd"
>
> If I wanted to recall the third item in the array, I would have to use
> ['sample'] not [2].
> If [2] did not exist, I can not assume [2] would equate to ['sample'].
>
> IOW, what you defined in the array, is what can be recalled.

Richard, odbc_fetch_array() IS defining the array. Just not the way he
expects.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: ODBC Connection [message #172744 is a reply to message #172743] Sun, 27 February 2011 20:06 Go to previous messageGo to next message
richard is currently offline  richard   
Messages: 213
Registered: June 2013
Karma: 0
Senior Member
On Sun, 27 Feb 2011 14:51:07 -0500, Jerry Stuckle wrote:

> On 2/27/2011 2:19 PM, richard wrote:
>> On Sun, 27 Feb 2011 10:49:26 -0800 (PST), bruceaj wrote:
>>
>>> On Feb 27, 1:36 pm, richard<mem...@newsguy.com> wrote:
>>>> On Sun, 27 Feb 2011 09:57:11 -0800 (PST), bruceaj wrote:
>>>> > I am connecting to an MS Access database. The connection and exec work
>>>> > fine. My problem is getting the data.
>>>>
>>>> > The following two statement work;
>>>> > $row = odbc_fetch_array($rs);
>>>> > $value = $row['Newspaper'];
>>>>
>>>> > If I change to
>>>> > $value = $row[1];
>>>>
>>>> > is_null($value) returns true.
>>>>
>>>> > What am I doing wrong or is an idiosyncrasy of using MS Access?
>>>>
>>>> > Bruce
>>>>
>>>> I'd say it's due to the fact you did not define $row[1].
>>>> Instead, you used 'newspaper' as the row identifier.
>>>> It can't find [1] so it reports an error.
>>>
>>> Okay??? I guess I don't know what I thought I knew!!
>>>
>>> Doesn't "odbc_fetch_array" returns an associative array. If so, can't
>>> I address the elements either by name "newspaper" or by index "1".
>>>
>>> One minor point, the index I should be using is "0" since the
>>> associative array is 0 based.
>>>
>>> Appreciate some suggestions on what I need to address the elements of
>>> my array, $row, via an index value.
>>>
>>> Thanks again...
>>>
>>> Bruce
>>
>> as I understand it, the array contents have to be defined.
>> If you define an array with names rather than number, then you can not
>> assume 0 is going to be the first array item. Or that 0 will be associated
>> with the first item by default.
>>
>> $item[0]="aaa"
>> $item[1]="bbb"
>> $item['sample']="ccc"
>> $item['data']="data"
>> $item[2]="ddd"
>>
>> If I wanted to recall the third item in the array, I would have to use
>> ['sample'] not [2].
>> If [2] did not exist, I can not assume [2] would equate to ['sample'].
>>
>> IOW, what you defined in the array, is what can be recalled.
>
> Richard, odbc_fetch_array() IS defining the array. Just not the way he
> expects.

okay thanks.
Re: ODBC Connection [message #172745 is a reply to message #172735] Sun, 27 February 2011 20:46 Go to previous messageGo to next message
bruceaj is currently offline  bruceaj
Messages: 30
Registered: September 2010
Karma: 0
Member
On Feb 27, 1:54 pm, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> On 2/27/2011 1:24 PM, bruceaj wrote:
>
>
>
>> On Feb 27, 1:07 pm, Luuk<L...@invalid.lan>  wrote:
>>> On 27-02-11 18:57, bruceaj wrote:
>
>>>> I am connecting to an MS Access database. The connection and exec work
>>>> fine. My problem is getting the data.
>
>>>> The following two statement work;
>>>> $row = odbc_fetch_array($rs);
>>>> $value = $row['Newspaper'];
>
>>>> If I change to
>>>> $value = $row[1];
>
>>>> is_null($value) returns true.
>
>>>> What am I doing wrong or is an idiosyncrasy of using MS Access?
>
>>>> Bruce
>
>>> This would probably tell more:
>>> print_r($row);
>
>>> --
>>> Luuk
>
>> Okay.. Thanks for the response.
>
>> Array ( [Newspaper] =>  Review [Year] =>  1887 [Month] =>  5 [Day] =>  20
>> [Page] =>  4 [Column] =>  3 [Father First] =>  Joe [Father Middle] =>
>> [Mother First] =>  [Mother Middle] =>  [Mother Maiden] =>  [First] =>
>> Daughter [Middle] =>  [Last] =>  Allen [Date Of Birth] =>  05/18/1887
>> [Date Of Baptism] =>  [Church] =>  [Counter] =>  1 [NewspaperKey] =>  1
>> [Comments] =>  )
>
>> Hope this helps..
>
>> Thanks again.
>
>> Bruce
>
> Which is exactly what you should get if you fetch as an associative
> array.  If you want to access the values by index, you need to fetch
> with an indexed array (odbc_fetch_row())/
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck...@attglobal.net
> ==================

Okay.. obdc_fetch_row() seems to have worked. I was under the opinion
that with an Associative Array the item could be addressed via either
a name or an index. I guess I'm wrong. Apparently an Associative Array
can only be indexed via a string value. Strange...

Thanks...

Bruce
Re: ODBC Connection [message #172746 is a reply to message #172744] Sun, 27 February 2011 20:52 Go to previous messageGo to next message
sheldonlg is currently offline  sheldonlg
Messages: 166
Registered: September 2010
Karma: 0
Senior Member
On 2/27/2011 3:06 PM, richard wrote:
> On Sun, 27 Feb 2011 14:51:07 -0500, Jerry Stuckle wrote:
>
>> On 2/27/2011 2:19 PM, richard wrote:
>>> On Sun, 27 Feb 2011 10:49:26 -0800 (PST), bruceaj wrote:
>>>
>>>> On Feb 27, 1:36 pm, richard<mem...@newsguy.com> wrote:
>>>> > On Sun, 27 Feb 2011 09:57:11 -0800 (PST), bruceaj wrote:
>>>> >> I am connecting to an MS Access database. The connection and exec work
>>>> >> fine. My problem is getting the data.
>>>> >
>>>> >> The following two statement work;
>>>> >> $row = odbc_fetch_array($rs);
>>>> >> $value = $row['Newspaper'];
>>>> >
>>>> >> If I change to
>>>> >> $value = $row[1];
>>>> >
>>>> >> is_null($value) returns true.
>>>> >
>>>> >> What am I doing wrong or is an idiosyncrasy of using MS Access?
>>>> >
>>>> >> Bruce
>>>> >
>>>> > I'd say it's due to the fact you did not define $row[1].
>>>> > Instead, you used 'newspaper' as the row identifier.
>>>> > It can't find [1] so it reports an error.
>>>>
>>>> Okay??? I guess I don't know what I thought I knew!!
>>>>
>>>> Doesn't "odbc_fetch_array" returns an associative array. If so, can't
>>>> I address the elements either by name "newspaper" or by index "1".
>>>>
>>>> One minor point, the index I should be using is "0" since the
>>>> associative array is 0 based.
>>>>
>>>> Appreciate some suggestions on what I need to address the elements of
>>>> my array, $row, via an index value.
>>>>
>>>> Thanks again...
>>>>
>>>> Bruce
>>>
>>> as I understand it, the array contents have to be defined.
>>> If you define an array with names rather than number, then you can not
>>> assume 0 is going to be the first array item. Or that 0 will be associated
>>> with the first item by default.
>>>
>>> $item[0]="aaa"
>>> $item[1]="bbb"
>>> $item['sample']="ccc"
>>> $item['data']="data"
>>> $item[2]="ddd"
>>>
>>> If I wanted to recall the third item in the array, I would have to use
>>> ['sample'] not [2].
>>> If [2] did not exist, I can not assume [2] would equate to ['sample'].
>>>
>>> IOW, what you defined in the array, is what can be recalled.
>>
>> Richard, odbc_fetch_array() IS defining the array. Just not the way he
>> expects.
>
> okay thanks.

Go to:
www.php.net
and look at
odbc_fetch_array, odbc_fetch_row, odbc_result

--
Shelly
Re: ODBC Connection [message #172747 is a reply to message #172745] Sun, 27 February 2011 20:55 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 2/27/2011 3:46 PM, bruceaj wrote:
> On Feb 27, 1:54 pm, Jerry Stuckle<jstuck...@attglobal.net> wrote:
>> On 2/27/2011 1:24 PM, bruceaj wrote:
>>
>>
>>
>>> On Feb 27, 1:07 pm, Luuk<L...@invalid.lan> wrote:
>>>> On 27-02-11 18:57, bruceaj wrote:
>>
>>>> > I am connecting to an MS Access database. The connection and exec work
>>>> > fine. My problem is getting the data.
>>
>>>> > The following two statement work;
>>>> > $row = odbc_fetch_array($rs);
>>>> > $value = $row['Newspaper'];
>>
>>>> > If I change to
>>>> > $value = $row[1];
>>
>>>> > is_null($value) returns true.
>>
>>>> > What am I doing wrong or is an idiosyncrasy of using MS Access?
>>
>>>> > Bruce
>>
>>>> This would probably tell more:
>>>> print_r($row);
>>
>>>> --
>>>> Luuk
>>
>>> Okay.. Thanks for the response.
>>
>>> Array ( [Newspaper] => Review [Year] => 1887 [Month] => 5 [Day] => 20
>>> [Page] => 4 [Column] => 3 [Father First] => Joe [Father Middle] =>
>>> [Mother First] => [Mother Middle] => [Mother Maiden] => [First] =>
>>> Daughter [Middle] => [Last] => Allen [Date Of Birth] => 05/18/1887
>>> [Date Of Baptism] => [Church] => [Counter] => 1 [NewspaperKey] => 1
>>> [Comments] => )
>>
>>> Hope this helps..
>>
>>> Thanks again.
>>
>>> Bruce
>>
>> Which is exactly what you should get if you fetch as an associative
>> array. If you want to access the values by index, you need to fetch
>> with an indexed array (odbc_fetch_row())/
>>
>
> Okay.. obdc_fetch_row() seems to have worked. I was under the opinion
> that with an Associative Array the item could be addressed via either
> a name or an index. I guess I'm wrong. Apparently an Associative Array
> can only be indexed via a string value. Strange...
>
> Thanks...
>
> Bruce

No, there are two different kinds of arrays.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: ODBC Connection [message #172748 is a reply to message #172745] Sun, 27 February 2011 21:02 Go to previous messageGo to next message
spambait is currently offline  spambait
Messages: 35
Registered: September 2010
Karma: 0
Member
In article <d4514447-c983-4a85-a8af-7df9eeba47ab(at)o14g2000prb(dot)googlegroups(dot)com>, bruceaj <bruceaj(at)bellsouth(dot)net> wrote:

> Okay.. obdc_fetch_row() seems to have worked. I was under the opinion
> that with an Associative Array the item could be addressed via either
> a name or an index. I guess I'm wrong. Apparently an Associative Array
> can only be indexed via a string value. Strange...

Nothing "strange" about it -- that's the entire point of an *associative*
array...
Re: ODBC Connection [message #172749 is a reply to message #172748] Sun, 27 February 2011 21:10 Go to previous messageGo to next message
bruceaj is currently offline  bruceaj
Messages: 30
Registered: September 2010
Karma: 0
Member
On Feb 27, 4:02 pm, spamb...@milmac.com (Doug Miller) wrote:
> In article <d4514447-c983-4a85-a8af-7df9eeba4...@o14g2000prb.googlegroups..com>, bruceaj <bruc...@bellsouth.net> wrote:
>
>> Okay.. obdc_fetch_row() seems to have worked.  I was under the opinion
>> that with an Associative Array the item could be addressed via either
>> a name or an index. I guess I'm wrong. Apparently an Associative Array
>> can only be indexed via a string value. Strange...
>
> Nothing "strange" about it -- that's the entire point of an *associative*
> array...

Okay... Thanks to all for the help..

Bruce
Re: ODBC Connection [message #172759 is a reply to message #172746] Mon, 28 February 2011 07:47 Go to previous messageGo to next message
P E Schoen is currently offline  P E Schoen
Messages: 86
Registered: January 2011
Karma: 0
Member
"sheldonlg" wrote in message
news:ikedis$8ou$1(at)news(dot)eternal-september(dot)org...

> Go to:
> www.php.net
> and look at
> odbc_fetch_array, odbc_fetch_row, odbc_result

With SQLite, you can use a qualifier to fetch the array as either numeric,
or associative, or both:
http://php.net/manual/en/function.mysql-fetch-array.php

array mysql_fetch_array ( resource $result [, int $result_type =
MYSQL_BOTH ] )

This may be helpful as well:
http://www.phpro.org/tutorials/Introduction-to-PHP-PDO.html

I had problems using associative arrays when, for instance, I wanted to
fetch a series of rows which might be

$db->exec("INSERT INTO tEmail (id,name,email) VALUES (
'$ID', '$Name', '$Email' )");

For some reason I was unable to use the associative indexes in a "for" loop
such as

for( $i = name; $i <= email; $i++)

but this was OK:

$line = 0;
while ($row = $qres->fetcharray(SQLITE3_BOTH)) {
for ($i = 0; $i < 2; $i++) {
$arr[$line][$i] = $row[$i];
}
$name = $arr[$line][1]; // should also be OK to use
$arr[$line][name];
$email = $arr[$line][2];
$line++;
}

I didn't spend much time with it. Since it worked with numeric indexes, I
was OK with that, but associative would have been clearer.

Paul
Re: ODBC Connection [message #172765 is a reply to message #172759] Mon, 28 February 2011 11:40 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 2/28/2011 2:47 AM, P E Schoen wrote:
> "sheldonlg" wrote in message
> news:ikedis$8ou$1(at)news(dot)eternal-september(dot)org...
>
>> Go to:
>> www.php.net
>> and look at
>> odbc_fetch_array, odbc_fetch_row, odbc_result
>
> With SQLite, you can use a qualifier to fetch the array as either
> numeric, or associative, or both:
> http://php.net/manual/en/function.mysql-fetch-array.php
>
> array mysql_fetch_array ( resource $result [, int $result_type =
> MYSQL_BOTH ] )
>
> This may be helpful as well:
> http://www.phpro.org/tutorials/Introduction-to-PHP-PDO.html
>
> I had problems using associative arrays when, for instance, I wanted to
> fetch a series of rows which might be
>
> $db->exec("INSERT INTO tEmail (id,name,email) VALUES (
> '$ID', '$Name', '$Email' )");
>
> For some reason I was unable to use the associative indexes in a "for"
> loop such as
>
> for( $i = name; $i <= email; $i++)
>
> but this was OK:
>
> $line = 0;
> while ($row = $qres->fetcharray(SQLITE3_BOTH)) {
> for ($i = 0; $i < 2; $i++) {
> $arr[$line][$i] = $row[$i];
> }
> $name = $arr[$line][1]; // should also be OK to use $arr[$line][name];
> $email = $arr[$line][2];
> $line++;
> }
>
> I didn't spend much time with it. Since it worked with numeric indexes,
> I was OK with that, but associative would have been clearer.
>
> Paul

What is the value of 'name' + 1?

Associative array indexes are not numeric, so you can't increment them.

And although SQLLite can return an array with both indexed and
associative arrays, odbc_fetch_array() doesn't.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: ODBC Connection [message #172775 is a reply to message #172765] Mon, 28 February 2011 18:48 Go to previous message
P E Schoen is currently offline  P E Schoen
Messages: 86
Registered: January 2011
Karma: 0
Member
"Jerry Stuckle" wrote in message
news:ikg1jr$u6q$1(at)news(dot)eternal-september(dot)org...

> What is the value of 'name' + 1?

> Associative array indexes are not numeric, so you can't
> increment them.

I was attempting to do what I have done in Borland Delphi, where array
indexes are always numeric, but can be referenced by enumerations that are
simply aliases for numeric values.

Here are ways to emulate that, but it seems too complicated to make it
worthwhile:
http://stackoverflow.com/questions/254514/php-and-enums
http://it.toolbox.com/blogs/macsploitation/enums-in-php-a-native-implementa tion-25228
http://www.satya-weblog.com/2008/03/search-in-keyindex-of-anphp-array.html

> And although SQLLite can return an array with both indexed
> and associative arrays, odbc_fetch_array() doesn't.

I don't know how SQLite does this, but essentially it must create the
equivalent of another associative array which has a 1:1 correspondence of
the text key indexes and a numeric value of the row of the array. I suppose
it would work to assign numeric variables with numeric row indexes, such as:

$nID=0; $nName=1; $nEmail=2;

Then it would probably be legal to use:

For( $i=$nID; $i<=$nEmail; $i++ )

Just some ideas. Thanks.

Paul
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: static vs global variable
Next Topic: SOCIAL NETWORK FOR PHP PLATFORM..
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Fri Nov 22 20:31:25 GMT 2024

Total time taken to generate the page: 0.02928 seconds