[PHP-DB] [BUG] DEFINITIVE: Postgresql Field Names with Underscores
If you have a query that selects fields of the same name from more than one table, BEWARE!!! Postgresql automatically adds a trailing underscore and a number to each field name on the second or subsequent occurrence in order to return a unique name for each field. PHP apparently removes these, creating a duplicate field name. I would expect the same to occur with table field names that actually contain an underscore (don't know whether Postgres allows underscores in field names). The result will be of course that when you use any Postgres function that retrieves a named field, there may be two fields that have the same name as far as PHP is concerned and you won't be able to identify the field by its underscored Postgres name. If you use pg_fetch_array then unpredictable things will occur as (presumably) the data from the first occurrence of the field name gets overwritten by the data of the second occurrence as fields are retrieved from the row. I found this occurred when I wrote my own fetch code as below: function pgFetchArray($rsid,$rownum) { $fldcount = pg_numfields($rsid); for ($fld=0;$fld<$fldcount;$fld++) { $fldname = pg_fieldname($rsid,$fld); $flddata = pg_result($rsid,$rownum,$fld); echo "row=$rownum fld=$fld fldname=$fldname value=$flddata"; $dArray[$fldname] = $flddata; $dArray[$fld] = $flddata; } while (list ($key, $val) = each ($dArray)) echo "$key=$val "; echo ""; return $dArray; } SUGGESTED RESOLUTION 1. In the query specification, select duplicate field names individually and use the AS keyword to specify a name that doesn't have an underscore in it. 2. Change any table field names that have underscores to remove them. -- ======= Patrick Dunford, Christchurch, NZ - http://pdunford.godzone.net.nz/ Do not be anxious about anything, but in everything, by prayer and petition, with thanksgiving, present your requests to God. -- Philippians 4:6 http://www.heartlight.org/cgi-shl/todaysverse.cgi?day=20010406 === Created by Mail2Sig - http://pdunford.godzone.net.nz/software/mail2sig/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] [BUG] Associative arrays and Postgresql
I wrote in another thread about having problems when storing data from a pgsql query into associative arrays using pg_fetch_array. In order to further test this behaviour I wrote my own pgFetchArray function to work basically the same way. This is the code: function pgFetchArray($rsid,$rownum) { $fldcount = pg_numfields($rsid); for ($fld=0;$fld<$fldcount;$fld++) { $fldname = pg_fieldname($rsid,$fld); $flddata = pg_result($rsid,$rownum,$fld); echo "row=$rownum fld=$fld fldname=$fldname value=$flddata"; $dArray[$fldname] = $flddata; $dArray[$fld] = $flddata; } while (list ($key, $val) = each ($dArray)) echo "$key=$val "; echo ""; return $dArray; } Here is one record from the query: row=0 fld=0 fldname=scheduleid value=27 row=0 fld=1 fldname=displaytext value=M10V PMT row=0 fld=2 fldname=descriptext value=Mitre 10 Visa Payment Due row=0 fld=3 fldname=url value=https://sec.westpactrust.co.nz/servlet/Banking?xtr=Logon row=0 fld=4 fldname=current value=t row=0 fld=5 fldname=reminder value=f row=0 fld=6 fldname=hideinsummary value= row=0 fld=7 fldname=occurrid value=35 row=0 fld=8 fldname=scheduleid value=27 row=0 fld=9 fldname=occurdate value=26/12/2000 row=0 fld=10 fldname=starttime value=00:00:00 row=0 fld=11 fldname=endtime value=00:00:00 row=0 fld=12 fldname=allday value=t row=0 fld=13 fldname=importance value=3 row=0 fld=14 fldname=repeats value= row=0 fld=15 fldname=descriptext value= row=0 fld=16 fldname=url value= scheduleid=27 0=27 displaytext=M10V PMT 1=M10V PMT descriptext= 2=Mitre 10 Visa Payment Due url= 3=https://sec.westpactrust.co.nz/servlet/Banking?xtr=Logon current=t 4=t reminder=f 5=f hideinsummary= 6= occurrid=35 7=35 8=27 occurdate=26/12/2000 9=26/12/2000 starttime=00:00:00 10=00:00:00 endtime=00:00:00 11=00:00:00 allday=t 12=t importance=3 13=3 repeats= 14= 15= 16= The interesting point is that fields 15 and 16 are given names by Postgres that include underscores (because the same field name occurs in both tables of the query). Yet when PHP gets the field names the _1 etc have been removed. Perhaps there is a problem with confusion of the names of the fields. I will try rewriting my query. -- =========== Patrick Dunford, Christchurch, NZ - http://pdunford.godzone.net.nz/ Do not be anxious about anything, but in everything, by prayer and petition, with thanksgiving, present your requests to God. -- Philippians 4:6 http://www.heartlight.org/cgi-shl/todaysverse.cgi?day=20010406 === Created by Mail2Sig - http://pdunford.godzone.net.nz/software/mail2sig/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DB] Is Sybase supported on Windows?
On 4 Apr 2001 04:12:37 -0700 AD in php.db, Javier Boluda said: >Hello, >I'm trying to connect via PHP to Sybase from Win'98 Having Personal Web Server >and I get the following error: >Fatal error: Call to unsupported or undefined function sybase_connect() > >I haven't found any dll named *sybase* for Windows. Is there any way of supporting >Sybase? There is a DLL in extensions calls php_sybase_ct.dll You either need to compile in support for sybase with PHP or dl a dynamic library. -- ======= Patrick Dunford, Christchurch, NZ - http://pdunford.godzone.net.nz/ Rejoice in the Lord always. I will say it again: Rejoice! -- Philippians 4:4 http://www.heartlight.org/cgi-shl/todaysverse.cgi?day=20010404 === Created by Mail2Sig - http://pdunford.godzone.net.nz/software/mail2sig/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP-DB] Fatal error: Call to unsupported or undefined functi on mysql_connect()
On 4 Apr 2001 06:54:45 -0700 AD in php.db, Brunner, Daniel said: >Hello... > >Either the Username or Password or Database does not exist... NO!. "Call to undefined function" means it doesn't know the name of the function you are calling. if the function name is correct you either need to load a mySQL library for PHP using the dl statement or you need to compile PHP with mySQL support enabled. Check with your server administrator. > >Do this > >$db =3D mysql_connect(server, $user, $password)=20 > or die ("Sorry something is wrong"); >$select =3D mysql_select_db("intranet", $db); > or die ("Sorry something is wrong"); > >That way you can see if it connects and or if the Database does >exist. > > >You can also delete $select as well so it would read. > >mysql_select_db("intranet", $db); > or die ("Sorry something is wrong"); > >That what I use > >That really might be the problem.. > > >Learn how to put in debug stuff. It's easier to see your >mistakesI know I had a bunch... > > > >Dan=20 > > > > >> -- >> From:Patrick Sch=E4fer >> Sent:Wednesday, April 4, 2001 7:41 AM >> To: PHP >> Subject: [PHP-DB] Fatal error: Call to unsupported or undefined >> function mysql_connect()=20 >>=20 >> Can anybody help me with this problem >>=20 >> Fatal error: Call to unsupported or undefined function = >mysql_connect() >> in >> dbopen.php on line 7 >>=20 >> $server =3D "localhost"; >> $user =3D "dbuser"; >> $password =3D "pass"; >> $db =3D mysql_connect($server, $user, $password); --> This is line 7 = >of >> my >> script >> $select =3D mysql_select_db("intranet", $db); >>=20 >> Thanks, >> Patrick >>=20 >>=20 >> --=20 >> PHP Database Mailing List (http://www.php.net/) >> To unsubscribe, e-mail: [EMAIL PROTECTED] >> For additional commands, e-mail: [EMAIL PROTECTED] >> To contact the list administrators, e-mail: >> [EMAIL PROTECTED] >>=20 >>=20 > > -- === Patrick Dunford, Christchurch, NZ - http://pdunford.godzone.net.nz/ Rejoice in the Lord always. I will say it again: Rejoice! -- Philippians 4:4 http://www.heartlight.org/cgi-shl/todaysverse.cgi?day=20010404 === Created by Mail2Sig - http://pdunford.godzone.net.nz/software/mail2sig/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP-DB] [BUG?] pg_fetch_array
I have a database running on PostgreSQL. My script runs an SQL query and then retrieves the data with calls to pg_fetch_array. It then stores each record for later use, looking it up in memory. What I have found is that pg_fetch_array is not reliable in terms of the key name in the associative array. To test this I retrieved data using a call to pg_fetch_array and then used the following code shown in the PHP help file to print out the fields and their data: while (list ($key, $val) = each ($row)) echo "$key => $val"; This will return each field twice: once with a numeric key, and once with a named key. However in some cases the named key does not return any data. Here is an example: 0 => 27 scheduleid => 27 1 => M10V PMT displaytext => M10V PMT 2 => Mitre 10 Visa Payment Due descriptext => 3 => https://sec.westpactrust.co.nz/servlet/Banking?xtr=Logon url => 4 => t current => t 5 => f reminder => f 6 => hideinsummary => 7 => 35 occurrid => 35 8 => 27 9 => 26/12/2000 occurdate => 26/12/2000 10 => 00:00:00 starttime => 00:00:00 11 => 00:00:00 endtime => 00:00:00 12 => t allday => t 13 => 3 importance => 3 14 => repeats => 15 => 16 => There are 17 fields in the result set (correct). You can see the problem occurring in field 2 and 3. The numeric key returns values but the named key doesn't. This doesn't occur on every single record, only on some records. The other problem is that there is no named key for when the same field name is returned a second time. Postgres names these fields the same except it adds "_1" on the end of the name. But this is evidently left unresolved by PHP. Fields 8, 15 and 16 are examples. The only reliable way I can see of being able to retrieve the data is to use numbered rather than fieldname references. It only seems to apply to a few fields and is without logic, since in some cases it does dereference correctly. -- === Patrick Dunford, Christchurch, NZ - http://pdunford.godzone.net.nz/ Rejoice in the Lord always. I will say it again: Rejoice! -- Philippians 4:4 http://www.heartlight.org/cgi-shl/todaysverse.cgi?day=20010404 === Created by Mail2Sig - http://pdunford.godzone.net.nz/software/mail2sig/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
RE: [PHP-DB] CSS versus Includes
On 31 Mar 2001 13:19:45 -0800 AD in php.db, Michael Geier said: >this post is about apples and oranges... > >CSS (Cascading Style Sheets) have nothing to do with includes. >They only have to do with formatting elements on a web page. >They can be written inside the document, or can referenced >externally via a tag. > >Includes can be anything from a configuration file, a block of >text, or a header or footer statement that works across multiple >pages, so you don't have to duplicate code. Including a CSS :) -- =========== Patrick Dunford, Christchurch, NZ - http://pdunford.godzone.net.nz/ Now to him who is able to do immeasurably more than all we ask or imagine, according to his power that is at work within us, to him be glory in the church and in Christ Jesus throughout all generations, for ever and ever! Amen. -- Ephesians 3:20-21 http://www.heartlight.org/cgi-shl/todaysverse.cgi?day=20010331 === Created by Mail2Sig - http://pdunford.godzone.net.nz/software/mail2sig/ -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]