[Solved] Strange count 'error'

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
Shendemiar
Forum Contributor
Posts: 404
Joined: Thu Jan 08, 2004 8:28 am

[Solved] Strange count 'error'

Post by Shendemiar »

This has been solved.

Main point in this was that i first made a query in phpmyadmin, and pasted it to my code, so save trouble. Usually it works just fine, but with COUNT it doesnt.

phpmyadmin adds an empty space after the COUNT and before the (whatever) like

Count(a)

becomes

Count (a)

And the later dont work with normal php code, it gives an syntax error, but pasting the query again into phpmyadmin, and it works just fine, thus the pain...
Last edited by Shendemiar on Tue Mar 02, 2004 4:55 pm, edited 1 time in total.
Shendemiar
Forum Contributor
Posts: 404
Joined: Thu Jan 08, 2004 8:28 am

Post by Shendemiar »

Even:

select count (*) from news;

Gives me that notice on phpmyadmin, and error in my code:

Error in query: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 '(*) from news' at line 1
Shendemiar
Forum Contributor
Posts: 404
Joined: Thu Jan 08, 2004 8:28 am

Post by Shendemiar »

New TRY:

I changed my php from CGI to module, and now lately i've been receiving these:

Notice: Undefined variable: url_query in d:\_palvelin\phpmyadmin-2.5.4\libraries\display_tbl.lib.php on line 1477

when i make trivial queries (usually count related) on phpmyadmin or in my project...

What is url_query?
Shendemiar
Forum Contributor
Posts: 404
Joined: Thu Jan 08, 2004 8:28 am

Post by Shendemiar »

CGI/Module, both the same behaviour...
Shendemiar
Forum Contributor
Posts: 404
Joined: Thu Jan 08, 2004 8:28 am

Post by Shendemiar »

I'm not looking for a complete answar... I would appriciate anything, even something like:

"It might be your apache..."
or
"Reinstall everything..."
etc...
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Well, i'd first get the latest stable version of phpMyAdmin, which is 2.5.6 as you maybe hitting a bug that's since been fixed. I'd also stick with the module version of PHP.

The 'undefined variable' notice is just down to your error_reporting setting. If you have error_reporting set to E_ALL then things like echo $foo; will throw up an undefined variable notice if $foo isn't set. You can tweak the error_reporting value in php.ini, a vhost section of httpd.conf or in a script itself using http://php.net/error_reporting
Shendemiar
Forum Contributor
Posts: 404
Joined: Thu Jan 08, 2004 8:28 am

Post by Shendemiar »

markl999 wrote:Well, i'd first get the latest stable version of phpMyAdmin, which is 2.5.6 as you maybe hitting a bug that's since been fixed. I'd also stick with the module version of PHP.

The 'undefined variable' notice is just down to your error_reporting setting. If you have error_reporting set to E_ALL then things like echo $foo; will throw up an undefined variable notice if $foo isn't set. You can tweak the error_reporting value in php.ini, a vhost section of httpd.conf or in a script itself using http://php.net/error_reporting
2.5.6 don't give the notice anymore, and i used other means to count records than count in sql statement, so i guess i'm clear for now...

I think it's good to keep maximum error reporting while im trying to learn it...
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

I think it's good to keep maximum error reporting while im trying to learn it.
I agree, and always use E_ALL. It's just handy to be able to lower it for third party apps as 90% of them would have a fit if they had to work under E_ALL conditions ;)
Shendemiar
Forum Contributor
Posts: 404
Joined: Thu Jan 08, 2004 8:28 am

Post by Shendemiar »

ÄGH...It came again, when i needed count elsewhere:

I have:
error_reporting(E_ALL);

And i Get:
Error in query:You have an error in your SQL syntax.

This time with:
$query=fetch_query("SELECT vote, count (pid) as co from games_requests where gid=$gamenro group by vote ");

I think that the query isn't the issue, it's everything that uses count. The same query goes fluently in phpmyadmin 2.5.6.

Can indexes and uniques etc effect that anyhow.

I have:
Apache/1.3.29 (Win32) PHP/4.3.4 running...
MySql 4.0.18
Shendemiar
Forum Contributor
Posts: 404
Joined: Thu Jan 08, 2004 8:28 am

Post by Shendemiar »

So the question is:

Why "Select count(*) from A" Works with phpmyadmin, but not within my code?

What settings in php.ini and httpd.conf could have any impact with count ?

It doesnt work either on phpED, and it has internal server/php/mysql, so it must be a syntax?

Here's a sample:

Code: Select all

<?php
    $query=("SELECT count (*) from games_requests");
    $yhteys = mysql_connect($DBC1, $DBC2, $DBC3) or die ("Error on connect:" . mysql_error());
    if(isset($yhteys))
    {
        mysql_select_db($DB, $yhteys);
        $haku = mysql_query($query, $yhteys) or die("Error in query:" . mysql_error());
        return $haku;
    }
    mysql_close($yhteys);
?>
Error in query: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 '(pid) from games_requests' at line 1
Shendemiar
Forum Contributor
Posts: 404
Joined: Thu Jan 08, 2004 8:28 am

Post by Shendemiar »

I think i solved it:

I used:
count (pid)

Instead of:
count(pid)

I use phpmyadmin to formalize many of my queries, it saves typing, but now i see that i isnt allways that beneficial...
User avatar
EvilWalrus
Site Admin
Posts: 209
Joined: Thu Apr 18, 2002 3:21 pm
Location: Springmont, PA USA

Post by EvilWalrus »

PLease refrain from multiple postings... this is not IRC. Please reedit, or condense your original post with the new information next time.
Post Reply