Re: [PHP] mysqli sql question

2011-08-31 Thread John Black

On 31.08.2011 11:23, Peet Grobler wrote:

Is it possible to get the actual sql that is being used to query or
update the database?
E.g
$sth = $dbh-prepare (update table set field=?, field2=? where id=?);
mysqli_bind_param ($sth, 'ssi', 'text1', 'text2', 10);
$sth-execute();

Something like $sth-sql? Or $dbh-sql?
Thanks in advance,
Peet


Hi Peet,

not sure if there is a method to echo the sql but you can set your 
development MySQL server to log all queries to a log file.
Use the log file with tail and you'll get a live view of all queries the 
server attempts to process.


Open my.cnf / my.ini and add the following line:
log= /path/to/log/mysqld_query.log
or
log=D:\logs\mysqld_query.log

More info here: http://dev.mysql.com/doc/refman/5.1/en/query-log.html

I hope this helps ... ohh and don't forget to clear the log every now 
and then because it will get HUGE quickly.

--
John



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] mysqli sql question

2011-08-31 Thread James Yerge
On 08/31/2011 05:23 AM, Peet Grobler wrote:
 Is it possible to get the actual sql that is being used to query or
 update the database?

 E.g
 $sth = $dbh-prepare (update table set field=?, field2=? where id=?);
 mysqli_bind_param ($sth, 'ssi', 'text1', 'text2', 10);
 $sth-execute();

 Something like $sth-sql? Or $dbh-sql?

 I want to see update table set field='text1', field2='text2' where id=10;


 Thanks in advance,
 Peet

Look up the EXPLAIN SQL function call.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] mysqli sql question

2011-08-31 Thread Peet Grobler
On 8/31/2011 1:38 PM, John Black wrote:
 Hi Peet,
 
 not sure if there is a method to echo the sql but you can set your
 development MySQL server to log all queries to a log file.
 Use the log file with tail and you'll get a live view of all queries the
 server attempts to process.
 

I already have this on the development system. I'm looking for something
for the live system that displays the SQL if a query fails (this is done
in an email to the developer's mailing list)

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



RE: [PHP] mysqli sql question

2011-08-31 Thread Jen Rasmussen
Peet,

Could you do something like this instead? This is using named placeholders
and a separate line for your statement
but I was able to get it to echo the statement in this manner. 

$sql = UPDATE table SET field1=:field1, field2=:field2 WHERE id=:id;
$sth = $dbh-prepare($sql);
$sth-execute(array(:field1=$field1,
   : field2=$ field2,
   : id=$id));

echo $sql; 

Hope that helps,
Jen

-Original Message-
From: Peet Grobler [mailto:p...@hivemind.net] 
Sent: Wednesday, August 31, 2011 4:24 AM
To: php-general@lists.php.net
Subject: [PHP] mysqli sql question

Is it possible to get the actual sql that is being used to query or
update the database?

E.g
$sth = $dbh-prepare (update table set field=?, field2=? where id=?);
mysqli_bind_param ($sth, 'ssi', 'text1', 'text2', 10);
$sth-execute();

Something like $sth-sql? Or $dbh-sql?

I want to see update table set field='text1', field2='text2' where id=10;


Thanks in advance,
Peet

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php