Re: RESOLVED(maybe):Warning: Cannot send session cookie
| From: | Daniel Grace | Date: | Fri, 28 Dec 2001 09:56:33 +0000 |
| Subject: | Re: RESOLVED(maybe):Warning: Cannot send session cookie | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-78925@lists.php.net to get a copy of this message | ||
"David Jackson" <david.j.jackson@pickledbeans.com> wrote in message
news:3558.63.165.192.135.1009508969.cqhost@webmail.cqhost.com...
> All --
> It appears that the problem was a table design problems,
> my primary index wasn't set to auto-increment? So I was trying to
> insert records with duplicate keys !!
> This of course leads to another question, how do I return SQL error
messages
> to the browser?
>
> Thanks,
> David
>
Out of habit, I abstract all of the MySQL functions to handle this. My
current setup for http://hosting.venura.net/ (still under
construction).
outputs error messages like this:
function sqlQuery($query, $secure = 0) {
$result = mysql_query($query);
if(!$result) {
if($secure) {
$query = '*** hidden ***';
}
else {
/* This is just an oddity from how I construct some queries, primarily
INSERTs. If all of your queries are on a single line of text with no
leading/trailing whitespace or you don't care about appearance, you can
delete this section of the code */
$query = explode("\n", $query);
foreach($query as $line => $text) {
$query[$line] = trim($text);
}
$query = implode("\n", $query);
}
die('<h1>Oops...</h1><p><b>Sorry, but something seems to have gone
terribly wrong...</b></p>
<pre>
MySQL Error Number: ' . htmlspecialchars(mysql_errno()) . '
MySQL Error Description: ' . htmlspecialchars(mysql_error()) . '
Query Text:
' . htmlspecialchars($query) . '
</pre>
<p>(Yes, you probably have found a bug.)</p>
');
} else return ($result);
}
This will dump the query, error number and error description whenever a SQL
query fails. You can set the optional second parameter ($secure) to true if
your query involves anything that you don't want the end-user to see, such
as updating a password or something like that.
disclaimer: I didn't check to see what database engine you're using. If
you're using MySQL, this should work, otherwise use something similiar.