473,399 Members | 2,478 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

query works in mysql(phpmyadmin) but not in php

30
Hi

This query works in mysql

Expand|Select|Wrap|Line Numbers
  1. SELECT id
  2. FROM FILE WHERE created = (
  3. SELECT max( created )
  4. FROM FILE ) 
But not in php

tried
Expand|Select|Wrap|Line Numbers
  1. $getid= " SELECT id FROM file WHERE created = (SELECT max(created) FROM file) ";
and
Expand|Select|Wrap|Line Numbers
  1. $getid= " SELECT 'id' FROM 'file' WHERE 'created' = (SELECT max('created') FROM 'file') "
;

but it does not work.

please help.
Aug 18 '10 #1
4 2994
zorgi
431 Expert 256MB
Since it works in phpmyadmin I can only assume its your PHP that creates the problem. Can you show us PHP code that handles the query. BTW you could also try

SELECT id FROM file ORDER BY created DESC LIMIT 1
Aug 18 '10 #2
Tinus
30
Expand|Select|Wrap|Line Numbers
  1. $getid= "SELECT 'id' FROM 'file' ORDER BY 'created' DESC LIMIT 1 ";
is giving
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 'SELECT 'id' FROM 'file' ORDER BY 'created' DESC LIMIT 1' at line 3

PHP

Expand|Select|Wrap|Line Numbers
  1. // Create the SQL query 
  2.         $query = " INSERT INTO `file` (`name`, `mime`,`size`,`data`,`created` ) 
  3.                      VALUES ('{$name}','{$mime}',{$size},'{$data}',NOW())"; 
  4.         $result = $dbLink->query($query); 
  5.         $getid= "SELECT 'id' FROM 'file' ORDER BY 'created' DESC LIMIT 1 ";
  6.         $theid=$dbLink->query($getid);
Aug 18 '10 #3
zorgi
431 Expert 256MB
An identifier may be quoted or unquoted. If you are quoting identifier than use backtick (“`”) not single quotes.
Aug 18 '10 #4
Tinus
30
Still getting
Success! Your file was successfully added!Error! Query failed:

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 'SELECT `id` FROM file ORDER BY created DESC LIMIT 1' at line 3

query sqlq is no good. File 'C:\Documents and Settings\Administrator\My Documents\Downloads\shares.txt' not found (Errcode: 2)

With
Expand|Select|Wrap|Line Numbers
  1. $getid= "SELECT `id` FROM file ORDER BY created DESC LIMIT 1 ";
  2.         $theid=$dbLink->query($getid);
and
Expand|Select|Wrap|Line Numbers
  1. $getid= "SELECT `id` FROM `file` ORDER BY `created` DESC LIMIT 1 ";
Aug 18 '10 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Sims | last post by:
Hi, I can use phpMyAdmin to export a script to create a table. But what is the best practice when it comes to updating a table? I could go around looking for difference between the 'old' and...
0
by: phpnube | last post by:
I used this php package to install on my system... (i had problems with the isapi package from php so im back to the cgi portion of PHP php-cgi.exe) PHP 5.0.0 installer - 26 July 2004 (CGI...
3
by: | last post by:
I use MySQL from my php page and from phpMyAdmin. In Windows Server, following query works fine. In Linux Server instead it returns error. The SQL Query is: SELECT DISTINCT a.id, a.container,...
2
by: Charles Alexander | last post by:
This is a really, really elementary (almost dumb) question. I have a php script I picked up elsewhere that I want to use to query my MySQL DB. I have phpMyAdmin. I'd like to somehow run this...
0
by: lynn | last post by:
Hello! I installed on my mac (panther) on /usr/local mysql4.1.8 php5 and apache2; I already had a data dir (called var) on another volume witch was linked to a previous mysql installation via...
4
by: starman7 | last post by:
I have a query that seems to kill the db for our website (causes the 'Too many connections' error). I would like to avoid this! Is there a way to test the query before the db goes down? I do not...
0
by: NewbieSupreme | last post by:
I'm using PHPMyAdmin on an Apache2Triad install (latest version; 5.x.x, which installs PHP5 and PHPMyAdmin 2.8 as well). In Access, I exported a table to a text file, tab-delimited, text qualifyer...
5
by: Marcus | last post by:
Hello, I am having a problem with a query in phpMyAdmin... it works fine on my localhost, but the exact same query produces an error in phpMyAdmin on my server: localhost: PHP 4.3.11, MySQL...
2
by: dipperdan | last post by:
Hi, i'm trying to execute the following query: SELECT CONCAT_WS(' ', g.genus_name, s.species_name, i.rank, i.infraspecies_name, conf.auth1, conf.auth2 ) AS scientific_name, cn.common_name,...
1
by: Shalini Bhalla | last post by:
I need to run a cross tab query on my table in phpmyadmin , is ther any way to do so......
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.