zoukankan      html  css  js  c++  java
  • 【学习笔记】初闻数据库php-mysql

    <?php
    
    $mySql = mysql_connect(SAE_MYSQL_HOST_M.':'.SAE_MYSQL_PORT,SAE_MYSQL_USER,SAE_MYSQL_PASS) or die('connect mysql fail'.mysql_error());
    
    $tableName = 'userInfo';
    
    mysql_select_db(SAE_MYSQL_DB,$mySql);
    
    $template = 
    'CREATE TABLE IF NOT EXISTS %s
    (
    id int,
    openId varchar(255),
    nickname varchar(255)
    )
    ';
    
    $sqlCmd     = sprintf($template,$tableName);//创建表
    $result     = mysql_query($sqlCmd,$mySql) or die('fail to create table'.mysql_error());
    
    $keyStr       = 'id,openId,nickname';
    $valueStr     = '1000,"125ssdDD","SSDWORD"';
    $sqlCmd        = sprintf('INSERT INTO %s(%s) VALUES (%s)',$tableName,$keyStr,$valueStr);
    $result     = mysql_query($sqlCmd,$mySql) or die('table not exit'.mysql_error());
    
    $sqlCmd        = sprintf('SELECT * FROM %s',$tableName);
    $result     = mysql_query($sqlCmd,$mySql)or die('fail to select'.mysql_error());//获取mysql对象
    var_dump($result);
    echo '<br/>';
    while($row = mysql_fetch_assoc($result)){//mysql_fetch_array($result,MYSQL_ASSOC);
        
        var_dump($row);
        
        }
    
    
    
    echo '<br/>';
    
    $sqlCmd     = sprintf('SELECT COUNT(*) FROM %s',$tableName);//获取行数
    $result     = mysql_query($sqlCmd,$mySql) or die('table not exit'.mysql_error());
    var_dump($result);
    echo '<br/>';
    
    $count      = mysql_fetch_row($result);
    echo 'There ars '.$count[0].' rows in table '.$tableName;
    echo '<br/>';
    
    
    //$sqlCmd     = 'DROP TABLE IF EXISTS userInfo';//删除表
    //mysql_query($sqlCmd,$mySql) or die('fail to drop table'.mysql_error());
    
    mysql_free_result($result);
    mysql_close($mySql);
    
    ?>

    关键词 CREATE ALERT DROP DATABASE TABLE INDEX SELECT  FROM WHERE LIMIT ORDER BY OR AND PRIMERY NULL IF NOT EXISTS INSERT INTO VALUE LIKE BETEWWN  

    都是很接近自然语言的东西,用的时候查查~~~~

  • 相关阅读:
    Winform/WPF实例中的相互操作
    如何在WPF中调用Winform控件
    实现页面的GZip或Deflate压缩。
    奇怪的JS 缺少函数问题
    JavaScript可以根据浏览器类别决定是否注册函数?
    readonly与const
    如何读取系统字体、颜色、大小?
    Javascript实现div的toggle效果小记及其它。
    ACCESS SELECT TOP N的问题
    如何将Dictionary绑定到Repeater?
  • 原文地址:https://www.cnblogs.com/flytu/p/5002302.html
Copyright © 2011-2022 走看看