Fork me on GitHub
Suzf  Blog

How-to use MySQL-python module

对于数据库操作,和 TCP/IP 的三次握手异曲同工之妙,建立连接,执行操作,断开连接。当然这就需要建立连接的工具

Python连接mysql的方案有oursql、PyMySQL、 myconnpy、MySQL Connector 等,不过本篇说的确是另外一个类库MySQLdb,MySQLdb 是用于Python链接Mysql数据库的接口,它实现了 Python 数据库 API 规范 V2.0,基于 MySQL C API 上建立的。

Reference

Package MySQL-python

Read more

Python MySQLdb test for select count(*) = zero

I use SELECT COUNT(*) FROM db WHERE <expression> to see if a set of records is null. So:

>>> cnt = c.fetchone()
>>> print cnt
(0L,)

My question is: how do you test for this condition?
I have a number of other ways to accomplish this. Is something like the following possible?

if cnt==(0L,):
    # do something
...

ImportError: libmysqlclient.so.18: cannot open shared object file

MySQL-python (1.2.5)

>>> import MySQLdb
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/Python2.7.3/lib/python2.7/site-packages/MySQLdb/__init__.py", line 19, in <module>
    import _mysql
ImportError: libmysqlclient.so.18: cannot open shared object file: No such file or directory
...

How-to: use Python send mail with To Cc and Bcc

#!/usr/bin/python
# -*- coding:utf-8 -*-

import smtplib
from email.mime.text import MIMEText

to = ['zfsu']
cc = ['zfsu','root']
bcc = ['jack']
from_addr = 'root'
message_subject = "Say Hello"
message_text = "Hello world"
message = "From: %s\r\n" % from_addr \
        + "To: %s\r\n" % "...
                
            

The Puppet Language Style Guide

Puppet Language Style Guide: Version 2.0.1Puppet: Version 3.7+

(Note: While the style guide maps to Puppet 3.7, many of its recommendations apply to Puppet 3.0.x and up.)

1. Terminology

The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “...

Use Python send mail

I recommend that you use the standard packages email and smtplib together to send Email. Please look at the following example (reproduced from the Python documentation). Notice that if you follow this approach, the "simple" task is indeed simple, and the more complex tasks (like attaching binary objects or send...

PHP 获取的时间和系统的时间不一致

问题描述:
最近发现自动发送工作日报的那个脚本出现了问题, 发送是大昨天的内容.
可能是系统时间或是服务器时间配置不正确,下面开始逐步排查.

^_^[11:04:26][root@master01 ~]#date
Thu Oct 22 11:05:33 CST 2015
^_^[11:05:33][root@master01 ~]#cat /etc/sysconfig/clock
ZONE="Asia/Shanghai"
#UTC=true
#ARC=false

<?php
//date_default_timezone_set('UTC');
date_default_timezone_set('CST/8.0');

$today...
                
            

What is Couchbase Server

Couchbase Server Screenshot.jpg
Read more