Hi ,
I’m trying to fetch data from mysql ,
whene i type a simple query as “select * from table” and use var dump very thing goes right
but when i user more complex query as "select * from table where name = name and …
nothing comes back ?? (this works if I’m not using ajax).
I’m slightly confused as to your context - are you referring to ajax as in the client side technology “asynchronous javascript and xml” ? If yes, then absolutely nothing database related should get anywhere near your front end*
*Unless you’re creating a db admin script like phpMyAdmin ???
I’m developing chat application using php and mysql (messages stored in mysql database) and jquey(ajax)
so i want my page to be refreshed every 5 seconds to print new messages , when i use simple query as i said before every thing works fine but when i use more complex query it returns nothing knowing that i have tried the same query in phpmyadmin and it works fine
Ok, cool so far. There’s a few things to check here though.
I just want to be 100% certain that you’re not sending the SQL query from the javascript/jquery on the front end, but are instead composing your SQL query in PHP at the very least (assuming you’re not using a db lib to build the query for you).
Do you have a logging solution written in to your php app yet? If not, you should (it’s more production friendly than accidentally leaving a var_dump() in your release candidate ) Here’s a good one: https://github.com/Seldaek/monolog also available on packagist if you’re using composer (recommended!)
Log the query that you’ve built
Log the mysql result set that comes back from the query
Log the response body that you’d be returning to the ajax request - does it match the payload format that your jquery app is expecting? If not, fix up the payload and/or jquery so that they’re in sync
Check the Content-Type that’s being returned with your payload - if php is throwing an exception, the content type could be getting forced to text/html instead of application/json (and the content body wont be JSON!)
Log any exceptions!
Use browser tools (firebug or developer tools in chrome) to verify what is being sent to the php server and what is coming back from the php server - this isn’t an alternative to the logging incidentally, as you’ll most likely still want some form of logging in production.
thanks for guiding me ,
i don’t know where the problem I’m beginner with ajax
but i solved this problem by using another query that do almost the same job ,
i don’t know where the problem I’m beginner with ajax