Reading about Setting the MySQL timezone per connection which I had to do like this:
db()->exec( "set time_zone = '+0:00'" );
Reading about Setting the MySQL timezone per connection which I had to do like this:
db()->exec( "set time_zone = '+0:00'" );
Reading about MySQL Connection Character Sets and Collations…
Read PHP MySQL BLOB today to learn how to work with BLOBs. Basically:
public function insertBlob($filePath,$mime){ $blob = fopen($filePath,'rb'); $sql = "INSERT INTO files(mime,data) VALUES(:mime,:data)"; $stmt = $this->conn->prepare($sql); $stmt->bindParam(':mime',$mime); $stmt->bindParam(':data',$blob,PDO::PARAM_LOB); return $stmt->execute(); } function updateBlob($id,$filePath,$mime) { $blob = fopen($filePath,'rb'); $sql = "UPDATE files SET mime = :mime, data = :data WHERE id = :id"; $stmt = $this->conn->prepare($sql); $stmt->bindParam(':mime',$mime); $stmt->bindParam(':data',$blob,PDO::PARAM_LOB); $stmt->bindParam(':id',$id); return $stmt->execute(); } public function selectBlob($id) { $sql = "SELECT mime, data FROM files WHERE id = :id"; $stmt = $this->conn->prepare($sql); $stmt->execute(array(":id" => $id)); $stmt->bindColumn(1, $mime); $stmt->bindColumn(2, $data, PDO::PARAM_LOB); $stmt->fetch(PDO::FETCH_BOUND); return array("mime" => $mime, "data" => $data); }
On my TODO list: MySQL Engines: MyISAM vs. InnoDB.
Reading about The utf8mb4 Character Set (4-Byte UTF-8 Unicode Encoding).
Needed to set a MySQL root password. Found this article which suggested a way when no password is yet configured:
mysqladmin -u root password NEWPASSWORD
And a way when a password is already configured:
mysqladmin -u root -p'oldpassword' password newpass
Note: you use ‘mysqladmin’ not ‘mysql’.
Found this article which has a handy ‘escape’ function:
// replace any non-ascii character with its hex code. function escape($value) { $return = ''; for($i = 0; $i < strlen($value); ++$i) { $char = $value[$i]; $ord = ord($char); if($char !== "'" && $char !== "\"" && $char !== '\\' && $ord >= 32 && $ord <= 126) $return .= $char; else $return .= '\\x' . dechex($ord); } return $return; }
Found this article today, Execute Multiple MySQL Queries from One String in PHP. It’s a work around for processing MySQL batch queries separated by semicolons.
Looking up the MySQL Date and Time Functions today.
It was harder to find what I was looking for than seemed reasonable, but eventually I figured out that you can convert a binary field from binary into a hexadecimal string using the MySQL HEX function.
Everything is easy once you know how!