I have recently uploaded my site to my hosting provider and I am getting a very odd error.
I have imported the exact same database as I was using on my local machine to the web host and it is telling me:
Warning: PDOStatement::execute(): SQLSTATE[42S22]: Column not found:
1054 Unknown column 'toppers_types.urlPath' in 'field list' in
/home/users/xxxxx/html/caketopper.co.uk/public_html/models/GalleryModel.php
on line 32
The weird thing is, is that the column does exist and I am 100% I am connecting to the correct database.
Here is the SQL concerned:
SELECT toppers.name, toppers.urlName, md.description, toppers_images.thumbSrc,
toppers_types.urlPath
FROM toppers_images, toppers_types, toppers
LEFT JOIN meta_descriptions AS md ON md.topperId = toppers.id
WHERE toppers_images.topperId = toppers.id
AND toppers_types.id = toppers.typeId
AND isPrimary = 1
If I take that SQL and put it into phpmyadmin on the webhost, the query runs as expected and I get results.
I am executing the query using PDO:
$r = $this->db->prepare($SQL) ;
$r->execute($PDOParams) ;
return $r->fetchAll(PDO::FETCH_OBJ) ;
Has anyone come across such an anomaly like this before? and if so how do I fix it?
There are plenty of the questions of this kind on Stackoverflow and almost all of them ended the same way:
- Oh, I forgot to update the actual database (rename the field, save the proper file etc.)
There is also possible issue with letter case (Unix version is case sensitive while Windows one is not).
Anyway - just test everything.
Run this query using PDO and see the results.
SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = 'toppers_types'
if field is absent - check server credentials and such
if present - copy-paste it's name to the query
Related
BACKGROUND: I am using PHPMyAdmin tool to run MySQL queries. MySQL version is 5.1.55. I have been using MySQL and this PHPMyAdmin tool for about 7 years and have never seen this error. I am trying to do a simple update query changing ne to gb (column = team, table = info). When I use PHPMyAdmin to try to make the changes,
I get the error message:
UPDATE `pickem`.`info` SET `team` = 'gb' WHERE CONVERT(`info`.`team` USING utf8) = \'ne\'.
QUESTION: What is going wrong here? What is the CONVERT Using UTF8 message coming from. How can I get this to just update the fields I want? I have tried to type the SQL code in myself ex: update info set team ="gb" where team = "ne" , but that does not work either. I get the error message:
There seems to be an error in your SQL query. The MySQL server error output below, if there is any, may also help you in diagnosing the problem
ERROR: Unknown Punctuation String # 22
STR: =\
SQL: update info set team =\"gb\" where team = \"ne\"
It seems the system is putting the slashes in there and it is not letting me do this simple update query.
I appreciate any advice on how to fix this.
Thanks!
You are using phpMyAdmin, right? Try using HeidiSQL.
Also check your PHP version, gpc_magic_quotes is already removed at PHP 5.4.0
I tried running your code on phpMyAdmin, removed the backslashes at \'ne\' and its running fine.
Try running a simple update query in HeidiSQL and check if the problem exists.
UPDATE `pickem`.`info` SET `team` = 'gb'
If it runs fine, modify it like
UPDATE `pickem`.`info` SET `team` = 'gb' WHERE `team` = 'ne'
Additional sidenote - check the encoding and data types. You might have overlooked something...
If your query runs fine on HeidiSQL, you can safely assume that something is wrong with your phpMyAdmin installation/configuration
EDIT:
Are the values you are providing contain '\' inside them? If so, you have to do it like
UPDATE `pickem`.`info` SET `team` = 'gb\\'
EDIT 2:
For the meantime, try to use this to solve your problem temporarily.
UPDATE `pickem`.`info` SET `team` = CONCAT('en') WHERE `team` = CONCAT('gb')
EDIT 3:
If all else fails, you probably should get this or this. Since you are on PHP 5.3, I am afraid to say that the gpc_magic_quotes option might have been enabled by your hosting provider. Contact them.
I have the following tables:
image_sources
character_trait_annotations
character_traits
characters
(and tables that are not pertinent to this problem). I am trying to use a stored procedure that looks for an ImageURL in image_sources where AnnotationID is equal to the one fetched from the code at random. That AnnotatonID belongs to character_trait_annotations table, which also has a CharacterID and a CharacterTraitID. The CharacterID is in characters table, which has CharacterName, and the CharacterTraitID is in character_traits, which has CharacterTraitName.
The code is to call the stored procedure with $character, $trait (which are CharacterName, CharacterTraitName, respectively), and attempt to fetch the ImageURL for it.
The stored procedure
The SQL code for the procedure is as follows:
CREATE PROCEDURE getImageURL(IN charName VARCHAR(35), IN traitName VARCHAR(100))
BEGIN
SELECT ImageSourceURL FROM image_sources WHERE
AnnotationID = (SELECT AnnotationID FROM character_trait_annotations WHERE CharacterID =
(SELECT CharacterID FROM characters WHERE CharacterName = charName) AND CharacterTraitName =
(SELECT CharacterTraitID FROM character_traits WHERE CharacterTraitName = traitName)
);
END;
However, when I call the procedure from PHP, I get this error: Unable to call stored procedure: Unknown column 'CharacterTraitName' in 'where clause'. I was able to create the stored procedure without complaint on the active server.
I check this procedure locally, on my own machine('s version of the database, in phpMyAdmin), by trying to create the stored procedure there to see what is going on, and I get this error: #1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 7
I even tried to enclose the column names and the table names with backticks, and it is telling me the same thing. What is wrong with this?
I figured it out; /* by "I", I mean a friend of mine */
OK, so what did you do?
I didn't have access to phpMyAdmin, MySQLConnect, or any other of those database editors, so I had to attempt making one of my own: http://dinotator.biokdd.org/ResearchProject/tableViewer.php . Right now, the only thing that works is the dropdown menu to select the tables.
I didn't have access to this up until today, and when I asked my friend, and he asked for a way to see the database, I gave him that. The problem he pointed out (and I should have seen) was the second condition in the subquery: CharacterTraitName =
(SELECT CharacterTraitID FROM character_traits WHERE CharacterTraitName = traitName) The stupid mistake that was made was trying to check for equality between CharacterTraitName and CharacterTraitID. Furthermore, CharacterTraitName column didn't exist in character_trait_annotations.
echo 'I feel dumb.';
I'm designing a web interface for my clients database (A .mdb MS Access file). I'm using an ODBC driver to connect to it and the odbc_ functions provided by PHP.
My problem is access's 'append' queries. From what I gather, it's just inserting more rows, but something is breaking the query from executing:
INSERT INTO test ( TITLE, [LEVEL], UNITID, TITLEM, COHORTPLUSOPTIONS )
SELECT \"OPTION ONLY\" AS Expr, Units.LEVEL, UnitOptionNumbers.ID, Units.TITLE,
UnitOptionNumbers.OPTIONCOHORT
FROM UnitOptionNumbers INNER JOIN Units ON UnitOptionNumbers.ID = Units.ID WHERE
(((UnitOptionNumbers.NOAWARD)=Yes));
The most helpful error message I can get is:
[ODBC Microsoft Access Driver] Too few parameters. Expected 1.
Which isn't helpful at all. I'm confident with mySQL, but I just cannot pinpoint the problem here. Please can you help me find the reason the query wont execute, or help me figure out a work around.
Thanks for your time.
I don't have enough reputation to comment but perhaps it could be a problem with the fact that your table "test" has two fields with the same name ("TITLE")
According to Microsoft:
"This error occurs only with Microsoft Access when one of the column names specified in a select statement does not exist in the table being queried."
The solution therefore is to change
SELECT \"OPTION ONLY\" AS Expr
to
SELECT 'OPTION ONLY'
It seems the original code attempted to fill the first field with a default text value I.e "OPTION ONLY". "OPTION ONLY" was being read as a column name it seems.
I have the following code:
$stmt = $db->query("SELECT * FROM tagged_cards WHERE card_tags LIKE '%test%';");
$cards_data = $stmt->fetchAll(\PDO::FETCH_ASSOC);
When I execute it, I get the following error:
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'card_tags' in 'where clause'
However, when I log into a database server and use MySQL console (or MySQL Workbench) for exactly the same query, it successfully executes with results as expected.
The table contains the mentioned column.
I already eliminated factors like typos, connecting by mistake to other database or possible caching. What can cause an error like this?
The error message is clear and unambiguous: there is no such column in the table. So, you have to connect a database where such field exists.
The ERROR clearly states that card_tags does not exist in tagged_cards table in your database.
Run this query to show column names in tagged_cards table. Ensure $db is connected to same database as in question.
$stmt = $db->query("DESCRIBE tagged_cards");
$columnNames = $stmt->fetchAll(PDO::FETCH_COLUMN);
print_r($columnNames);
The following table seems to show that there are 2 id fields which should be impossible.
The reason for this is #2 has a leading space
The above query returns Array ([0] => id [1] => id ) in browser, so check for leading spaces if table name seems correct.
I have a website with a sales and wanted page, which uses a query to return all of the sales & wanted ads into a recordset. It's been working for 4-5years without incident, but suddenly stopped working on Friday. My ISP tell me they have implemented v5 of MySQL, which seems to have caused the problem.
The query is below:
$query = "select * from $table order by uidno desc limit $from,$max_results";
It's executed via the following command
$recordset = mysql_query($query);
if($recordset == false)
{
echo("Could not retrieve comment. Please try later<br>");
echo("060211<br>");
return;
It's no longer able to load the comments into the recordset. Also the statement to populate the table is no longer populating the fields in the table correctly, though a new row is being created.
The statement is below:
$inputdata = "INSERT INTO $table(date,name,email,suggestion) values('$today','$inputname','$email','$suggestion')";
And it is executed via:
$outcome = mysql_query($inputdata);
The structure of the table is as follows:
uidno int(11) extra=AUTO_INCREMENT Null=no default = none
date date default 0000-00-00
Name varchar(60)
Email varchar (60) Null=yes Default = NULL
Suggestion blob attrbutes=binary null=no
Please help - I don't understand what changes I need to make to the syntax to make these queries compatible with MYSQL v5.
Update:
I added the echo mysql_error(); and it appears to output the following:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-10,10' at line 1
So this indicates an error in the syntax - but I've no idea what the error is.
http://dev.mysql.com/doc/refman/5.0/en/select.html
The LIMIT clause can be used to constrain the number of rows returned by the SELECT statement. LIMIT takes one or two numeric arguments, which must both be nonnegative integer constants (except when using prepared statements).
Column, index, stored routine, and
event names are not case sensitive on
any platform, nor are column aliases
so your lowercase column names in code and upper case column names in mysql structure should not be the problem.