11 Replies - 1378 Views - Last Post: 02 August 2013 - 09:34 PM Rate Topic: -----

#1 codespook   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 201
  • Joined: 31-October 12

Fatal error: Undefined class constant 'FETCH_NAMES'

Posted 01 August 2013 - 09:35 PM

I get this in the original code where I'm trying to show the contents of the table. I researched a bit last night and discovered that it could be a compatability issue so I edited my .htaccess file to make it work with php 5.3. Not the fix though (although the code needed updated anyways:) More looking around tells me that $show is not defined...but it is and for some reason the code tinks it's a constant? Here's the code.

<?php


$show = $conn-> prepare( "SELECT username, subject, contact, comment, date FROM rcomments WHERE page = ? ORDER BY time" );
	$show->execute(array($_SERVER['REQUEST_URL']));
	$show->SetFetchMode(PDO::FETCH_NAMES,$show);
	foreach ($show as $row);
	    {
	    echo $row, PHP_EOL;	    }





?>




The code is similiar to what I saw in the intro to PDO tutorial here. (edited by yours truly:) I did change teh Fetch_names and also after (PDO::Fetch_Names, it had a 0. I did not know what the 0 was so I experimented by putting in the $show. No fix though.
http://php.net/manua...ement.fetch.php Actually fetch_* is the constant. So if I am wanting to return the names of the rows and their designated values from the tables to show, what exactly do I have to define this as?

Thanks

Is This A Good Question/Topic? 0
  • +

Replies To: Fatal error: Undefined class constant 'FETCH_NAMES'

#2 Martyr2   User is online

  • Programming Theoretician
  • member icon

Reputation: 5552
  • View blog
  • Posts: 14,558
  • Joined: 18-April 07

Re: Fatal error: Undefined class constant 'FETCH_NAMES'

Posted 01 August 2013 - 09:44 PM

You mean PDO::FETCH_NAMED?

Quote

PDO::FETCH_NAMED (integer)

Specifies that the fetch method shall return each row as an array indexed by column name as returned in the corresponding result set. If the result set contains multiple columns with the same name, PDO::FETCH_NAMED returns an array of values per column name.


I assume this is what you were trying to specify. FETCH_NAMED not FETCH_NAMES

:)
Was This Post Helpful? 1
  • +
  • -

#3 codespook   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 201
  • Joined: 31-October 12

Re: Fatal error: Undefined class constant 'FETCH_NAMES'

Posted 01 August 2013 - 09:50 PM

Not sure where I got names then but yeah....let me test lol
Thanks!
Was This Post Helpful? 0
  • +
  • -

#4 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4278
  • View blog
  • Posts: 13,573
  • Joined: 08-June 10

Re: Fatal error: Undefined class constant 'FETCH_NAMES'

Posted 01 August 2013 - 10:28 PM

if you want to get the name of the table’s field, the experimental getColumnMeta() is the method for you.
Was This Post Helpful? 1
  • +
  • -

#5 codespook   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 201
  • Joined: 31-October 12

Re: Fatal error: Undefined class constant 'FETCH_NAMES'

Posted 01 August 2013 - 11:49 PM

Will that get the data that was inputted as well?
Was This Post Helpful? 0
  • +
  • -

#6 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4278
  • View blog
  • Posts: 13,573
  • Joined: 08-June 10

Re: Fatal error: Undefined class constant 'FETCH_NAMES'

Posted 01 August 2013 - 11:55 PM

did you read the description?
Was This Post Helpful? 0
  • +
  • -

#7 codespook   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 201
  • Joined: 31-October 12

Re: Fatal error: Undefined class constant 'FETCH_NAMES'

Posted 02 August 2013 - 12:19 AM

Sorry. I just did. Thanks. I'll change it
Was This Post Helpful? 0
  • +
  • -

#8 codespook   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 201
  • Joined: 31-October 12

Re: Fatal error: Undefined class constant 'FETCH_NAMES'

Posted 02 August 2013 - 04:29 AM

Had it working but now I broke it. At first I was getting a scope error so I could only fix that by changing the code to be different than the php.net example. Now the weird thing is, if I put this php file at the beginning of the page (before any html) with the session.php script I wrote, I get no error, no weird output. But if I include it above the form, where it is supposed to go, since it will show all the comments there once they are inserted into the database, it shows me the output of my select statement.

Here's the include code.

<?php
include './includes/rcomments.php';
?>



But even more, here is all the code I changed in the rcomments file. As I said, I had to get rid of a scope error so I I mixed the code. (obviously in a bad way:)

<?php

$show = $DB-> prepare("SELECT username, subject, contact, comment, date FROM rcomments WHERE page = ? ORDER BY time");
	$show->execute(array($_SERVER['REQUEST_URL']));
	$show->getColumnMeta(0);
	var_dump($show);




?>




Before I did that code, I wrote this :
<?php
$select = $DB->query('SELECT * FROM rcomments');
//just as a test query for now
$meta = $select->getColumnMeta(0);
var_dump($meta);
?>



I got this error Fatal error: Call to a member function query() on a non-object
Even global variables got the same error. (I'd try to avoid global variables for now though since with the luck I'm having I'd duplicate them on an accident and get more errors:)

Ok I think that's it for now. Thanks!

This post has been edited by codespook: 02 August 2013 - 05:49 PM

Was This Post Helpful? 0
  • +
  • -

#9 Dormilich   User is offline

  • 痛覚残留
  • member icon

Reputation: 4278
  • View blog
  • Posts: 13,573
  • Joined: 08-June 10

Re: Fatal error: Undefined class constant 'FETCH_NAMES'

Posted 02 August 2013 - 04:38 AM

hm, why is one snippet using $conn for the connection and the other $DB ?
Was This Post Helpful? 0
  • +
  • -

#10 codespook   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 201
  • Joined: 31-October 12

Re: Fatal error: Undefined class constant 'FETCH_NAMES'

Posted 02 August 2013 - 05:38 AM

Forgot to change the name of the variable when I copied the code I think. $conn was mine. I copied the code from php.net and edited the select statement, just forgot to change the variable. I didnt do that on my site. Just here as I had deleted that particular code I had before trying to figure out what was wrong.
Was This Post Helpful? 0
  • +
  • -

#11 codespook   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 201
  • Joined: 31-October 12

Re: Fatal error: Undefined class constant 'FETCH_NAMES'

Posted 02 August 2013 - 05:50 PM

now i changed it. Still getting error though
Was This Post Helpful? 0
  • +
  • -

#12 codespook   User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 201
  • Joined: 31-October 12

Re: Fatal error: Undefined class constant 'FETCH_NAMES'

Posted 02 August 2013 - 09:34 PM

At this moment it is fixed:) I passed $DB to a function as prameter, no error. I'll wait and see though if it works when the entire script is complete:) That and my session error I fixed yesterday.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1