Jump to content

mysql_query and phpmyadmin result is different


sniperscope

Recommended Posts

Hello

I am facing this kind of problem first time in my life. After a search in google, i found that many people have same problem.

 

My sql query works at a.php but fail at b.php

I run same query in phpmyadmin gives me correct result.

 

a.php and b.php connecting database by using same include file.

 

cn.php

$cn	= mysql_connect("localhost", "username", "pass");
mysql_select_db("sdb", $cn);	
mysql_set_charset('utf8',$cn);

 

Here is my sql query:

 

include('inc/cn.php');
$sql = "SELECT COUNT(" .date("D"). ") AS total_user FROM staff WHERE " .date("D"). " != '~'";

Link to comment
Share on other sites

php and phpmyadmin are not same, you can try to set page and sql encoded

How this can be? Could you please little specific.

 

Regards

 

three encoded need check:

file encoded

php encoded

mysql encoded

 

check file encoded first, you will see choose encoding when save as php file, choose UTF8

Link to comment
Share on other sites

You are either (a) using the wrong server, (b) using the wrong database, © looking at the wrong file and code, and/or (d) running the wrong query.

 

Hello

 

(a) I am using correct server

(b) No i am not using wrong database because database connection is in inc/cn.php and all files in the site using that file for db connection

© No, I've checked maybe 50 times word by word for both query.

(d) No, I even copy entire query from working page to NON-working page. Same query fail

 

@smoseley:

Here is the result of echo: Resource id #3

 

I am facing this kind of weird problem first time in my life.

Link to comment
Share on other sites

This is theoretically impossible, assuming it's the same query, run on the same server, using the same user and database. How would it execute differently on a different page through the same PHP parser? Assuming it runs at all, we know that isn't happening.

 

I haven't tested enough versions of phpMyAdmin, but I've used the heck out of the versions I have. I've never run into an issue where I copy working SQL to/from phpMyAdmin and it won't execute (assuming I wasn't giving it bad values in the first place).

 

This is a silly mistake on your end. Check the obvious places, cause it's going to be there.

Link to comment
Share on other sites

 

three encoded need check:

file encoded

php encoded

mysql encoded

 

check file encoded first, you will see choose encoding when save as php file, choose UTF8

 

Dear derrck

You were right. I have checked file and php encoding.

 

Stupid guy who sitting next desk create file in Shift_JIS format and i didn't checked.

After your post, i have checked encoding and change into correct encoding. It is working now.

 

I really want to thank everyone who tried help me out. Without you guys probably i would have 2-3 more days headache.

 

Have a great days.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.