Backend Development Solutions for MySQL Data Storage, SMTP Email, Outlook Compatibility, and pChart Image Generation
This article summarizes practical backend techniques for storing associative arrays in MySQL using PHP serialization or JSON, sending reliable SMTP emails with PHPMailer, handling Outlook HTML and image display issues, and generating charts with the pChart library, providing code examples and configuration tips.
During a migration of a reporting system, the team needed to store multiple bug‑related numeric fields efficiently in MySQL. Because the traditional column approach would waste resources and degrade query performance, they chose to keep the data as an associative array and serialize it.
Example array definition:
$bugInfos = array("bugCount" => "10", "bugFixed" => "5", "bugLater" => "10");To store the array, PHP's serialize() or json_encode() functions can convert it to a string before inserting it into the database, and later unserialize() or json_decode() can restore the original array.
// Before writing to the database
$bufInfos_serialize = serialize($bugInfos);
$bugInfos_json = json_encode($bugInfos);
// After reading from the database
$bufInfos_restore = unserialize($bufInfos_serialize);
$bufInfos_dejson = json_decode($bugInfos_json, true);For email notifications, the built‑in mail() function was deemed insufficient for reliable sender information and attachments, so the team switched to SMTP using PHPMailer. After installing class.phpmailer.php and class.smtp.php , a mail object can be created:
$mail = new PHPMailer();
$mail->SetFrom($mailFrom, $realName); // e.g. $mail->SetFrom("[email protected]", "奇效管理");
$mail->SMTPDebug = 1; // 0 = off, 1 = errors, 2 = messages onlyOutlook clients do not render HTML5 or external stylesheets well; using inline CSS and table‑based layouts is recommended. To display images in Outlook, embed them as attachments or use base64‑encoded data URIs. The Data URI scheme format is:
data:image/png;base64,1A2B3C4D5E...9QBase64 encoding is widely supported and convenient for small images, though it increases payload size. The article also covers generating chart images with the PHP pChart library, which relies on the GD extension. After downloading the library, developers can set font properties for Chinese characters and choose between Render() (save without output) or autoOutput() (output to browser) to produce various chart types.
Overall, the guide provides concrete code snippets and configuration advice for backend developers dealing with data serialization, SMTP email delivery, Outlook compatibility, and dynamic chart generation.
360 Quality & Efficiency
360 Quality & Efficiency focuses on seamlessly integrating quality and efficiency in R&D, sharing 360’s internal best practices with industry peers to foster collaboration among Chinese enterprises and drive greater efficiency value.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.