Jump to content

Echoing mysql query


kristen

Recommended Posts

Normally, when I run a query, it is in this format:

 

$query = "SELECT * FROM table where id='$id'";

$result = mysql_query($query); 

$row = mysql_fetch_array($result);

echo $query;

 

which I like, because then I can add that "echo $query;" at the end and make sure all my variables are passing correctly. However, now I am forced to work within someone elses code, and I need to be sure that I am querying what I want to be querying, and the format is like this:

 

return $this->_db->sql_select_one("table", '*', array('id'=>$id));

return array();

 

How can I print out what the query is that I am using?

 

Thanks for any help, I am fairly new at this and I am driving myself crazy here!!

 

Link to comment
Share on other sites

Depending on the library being used, there may not be any way of doing that, if for example they are using prepared statements. 

 

The first thing you need to do, is take a look at the database class and analyze it.  See if it provides any sort of debugging switches you can turn on.  You will need to understand how the library works.  When you get errors, you may have to take a look at the mysql error returned and use that to reverse engineer the problem.

Link to comment
Share on other sites

Thanks for the quick reply.

 

Re: analyzing errors - how about printing them out in full? All I get right now is "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 '0 LIMIT 1' at line 1"

Link to comment
Share on other sites

Unfortunately that is all that's available from the mysql_error().

 

You can always go into the class and alter it to provide you a better form of debugging, or use it to derive a new class that has additions for your benefit.  This is one of the benefits of oop.

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.