【学习笔记】初闻数据库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
都是很接近自然语言的东西,用的时候查查~~~~