sniperscope Posted July 4, 2012 Share Posted July 4, 2012 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"). " != '~'"; Quote Link to comment Share on other sites More sharing options...
requinix Posted July 4, 2012 Share Posted July 4, 2012 Echo your queries and make sure they are what you think they are. And wtf is with your table structure? Columns for each day of the week? That screams of an unnormalized database. Quote Link to comment Share on other sites More sharing options...
sniperscope Posted July 4, 2012 Author Share Posted July 4, 2012 yes, columns for each day of the week. Print echo that query and run it in the phpmyadmin returns data as i aspect(17 records). But php pages bring entire staff. Quote Link to comment Share on other sites More sharing options...
sniperscope Posted July 5, 2012 Author Share Posted July 5, 2012 Any help please. Quote Link to comment Share on other sites More sharing options...
derrck Posted July 6, 2012 Share Posted July 6, 2012 try to add `` on tablename Quote Link to comment Share on other sites More sharing options...
sniperscope Posted July 6, 2012 Author Share Posted July 6, 2012 Thanks for reply. I've just tested and no hope. Still same. Quote Link to comment Share on other sites More sharing options...
derrck Posted July 6, 2012 Share Posted July 6, 2012 php and phpmyadmin are not same, you can try to set page and sql encoded Quote Link to comment Share on other sites More sharing options...
sniperscope Posted July 6, 2012 Author Share Posted July 6, 2012 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 Quote Link to comment Share on other sites More sharing options...
requinix Posted July 6, 2012 Share Posted July 6, 2012 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. Quote Link to comment Share on other sites More sharing options...
smoseley Posted July 6, 2012 Share Posted July 6, 2012 echo $sql; Quote Link to comment Share on other sites More sharing options...
derrck Posted July 6, 2012 Share Posted July 6, 2012 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 Quote Link to comment Share on other sites More sharing options...
sniperscope Posted July 6, 2012 Author Share Posted July 6, 2012 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. Quote Link to comment Share on other sites More sharing options...
xyph Posted July 6, 2012 Share Posted July 6, 2012 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. Quote Link to comment Share on other sites More sharing options...
sniperscope Posted July 6, 2012 Author Share Posted July 6, 2012 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.