note 83255 added to ref.mysql
| From: | joachimb at gmail dot com | Date: | Fri, 16 May 2008 21:28:41 +0000 |
| Subject: | note 83255 added to ref.mysql | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-139459@lists.php.net to get a copy of this message | ||
Lazy Man's Logging:
<?php
/// Creates a table called $table as (id, when, message) if none such exists, and inserts a row
with $message in it.
/// If no connection details are given, it uses the current database connection. Same goes for
$database and $when.
///
/// @returns TRUE on success or FALSE on failure.
///
/// @example mysql_put_contents("orders", "I CAN HAZ CHEEZBURGER?",
"mysite", NULL, "127.0.0.1:3306", "mysite_user", "secret")
or die(mysql_error());
/// @example mysql_put_contents("guestbook", "Longcat says: I'm
loooooooooooong") or die("Errorz!");
function mysql_put_contents($table, $message, $database = NULL, $when = NULL, $host = NULL, $user
= NULL, $pass = NULL) {
if($host)
mysql_connect($host, $user, $pass);
if($database)
mysql_select_db($database);
$qry = "CREATE TABLE IF NOT EXISTS
$table (
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
when TIMESTAMP DEFAULT NOW(),
message TEXT NOT NULL
);";
$result = mysql_query($qry);
if($result === FALSE)
return FALSE;
$qry = "INSERT INTO $table VALUES(NULL, ".($when ? $when :
'NULL').", '".mysql_real_escape_string($message)."');";
$result = mysql_query($qry);
if($result === FALSE)
return FALSE;
return TRUE;
}
?>
----
Server IP: 212.63.193.10
Probable Submitter: 193.11.187.139
----
Manual Page -- http://www.php.net/manual/en/ref.mysql.php
Edit -- https://master.php.net/note/edit/83255
Del: integrated -- https://master.php.net/note/delete/83255/integrated
Del: useless -- https://master.php.net/note/delete/83255/useless
Del: bad code -- https://master.php.net/note/delete/83255/bad+code
Del: spam -- https://master.php.net/note/delete/83255/spam
Del: non-english -- https://master.php.net/note/delete/83255/non-english
Del: in docs -- https://master.php.net/note/delete/83255/in+docs
Del: other reasons-- https://master.php.net/note/delete/83255
Reject -- https://master.php.net/note/reject/83255
Search -- https://master.php.net/manage/user-notes.php