Posts Tagged ‘mysql’

Bu örnekte _swedish_ci karekter setindeki bir veritabanını _turkish_ci setine çeviriyoruz. Kullanmadan önce yedek almayı unutmayın!


<?

$host = "localhost";
$user = "root";
$pass = "password";
$db =   "database";

_connect($host, $user, $pass);
mysql_select_db($db);

$eski = ’utf8_swedish_ci‘;
$yeni = ’utf8_turkish_ci‘;
$cset = ’utf8‘;

function sorgula($sql) {
    $rs = mysql_query($sql);
    if (!$rs) {
        $message  = ’Hata: ‘ . mysql_error() . "\n<br>";
        $message .= ’Sorgu: ‘ . $sql . "\n<br>";
        die($message);
    }
    return $rs;
}

$tablolar = sorgula("SHOW TABLES");
$  = "<html xmlns=\"http://www.w3.org/1999/xhtml\"><head>";
$html .= "<meta http-equiv=\"Content-type\" content=\"text/html; charset=utf-8\" /></head>";

print $html. ’<body><pre>‘;

while ($sutunlar = mysql_fetch_row($tablolar)) {
    $table = mysql_real_escape_string($sutunlar[0]);
    sorgula("ALTER TABLE `$table` DEFAULT CHARACTER SET $cset");
    echo "$table $cset e dönüştü! \r\n";
    $rs = sorgula(" SHOW FULL FIELDS FROM `$table` ");
    while ($sutun=mysql_fetch_assoc($rs)) {
        if ($sutun['Collation']!=$eski)
            continue;
        $field = mysql_real_escape_string($sutun['Field']);
        sorgula ("ALTER TABLE `$table` CHANGE `$field` `$field` $sutun[Type] CHARACTER SET $cset COLLATE $yeni");
        echo "$table tablosu $field alani $yeni karekter setine dönüştürüldü\r\n";
    }
}
print "</pre></body></html>";
?>

Bookmark and Share
Tags: , , ,

Tags: , , ,

19
Feb

Python ile basit bir html form generator (üreteç)

   Posted by: İsmail ÇAKIR    in python


import sys
import 

tablename = ""
mhost = ""
muser = ""
mpasswd = ""
mdb= ""

def head():
    head = """
    <><head>
    <style>
    .minput {
        border: 1px solid #fdfcf7;
        font-family: "Times New Roman", Times, serif;
        font-style: bold;
        font-size: 14px;
        color: #454743;
    }

    .mlabel {
        font-family: "Times New Roman", Times, serif;
        font-style: bold;
        font-size: 13px;
        color: #e7363e;
    }
    </style></head><body>< action="" method="post">
    """
    return head

def sub():
    sub = """
        </form></body></html>
    
    """
    return sub

def insert():
    pass

def update():
    pass

def input(name, label = None):
    if not label:
        label = name
    return ‘<label style="mlabel">%s:</label><input style="minput" name="%s" type=text />’ % (label, name)

def clean(mrow):
    pass

def deneme():
    try:
        conn = MySQLdb.connect (host = mhost, user = muser, passwd = mpasswd, db = mdb)
        cursor = conn.cursor ()
        msql = ‘select column_name from information_schema.columns where table_name="%s"’ % tablename
        cursor.execute (msql)
    except MySQLdb.Error, e:
        print "Error %d: %s" % (e.args[0], e.args[1])
        sys.exit (1)

    row = cursor.fetchall ()
    print head()
    for  r in range(len(row)):
        print input("".join(row[r]))
    print sub()
    cursor.close ()
    conn.close ()

if __name__ == "__main__" :
    deneme()

Bookmark and Share
Tags: , , , , , , ,

Tags: , , , , , , ,

Switch to our mobile site