1. [代码] ?php/* * mysql数据库基本操作 */ $db = mysqli_connect('192.168.10.102','root','test@100msh.com','yzhtmp'); //var_dump($db); // 创建数据库// $create = 'create table xin(id int, name char(20), pwd char(32)) charset = ut
1. [代码]
<?php /* * mysql数据库基本操作 */ $db = mysqli_connect('192.168.10.102','root','test@100msh.com','yzhtmp'); //var_dump($db); // 创建数据库 // $create = 'create table xin(id int, name char(20), pwd char(32)) charset = utf8'; // $b_create = mysqli_query($db,$create); // // if ($b_create) { // echo "创建数据库成功!"; // } else { // echo "创建数据库失败!"; // } $insert = 'insert into xin values(111,"你好","123456")'; //$delete = 'delete from xin where id = 111'; mysqli_query($db,"set names utf8"); $b_insert = mysqli_query($db,$insert); if ($b_insert) { echo "数据插入成功!"; } else { echo "数据插入失败!"; } mysqli_close($db); ?>
2. [代码]获得查询结果
<?php /* * select */ $db = mysqli_connect('192.168.10.102','root','test@100msh.com','yzhtmp'); $select = 'select * from xin'; $result = mysqli_query($db,$select); $num = mysqli_num_rows($result); echo "$num"; echo '<br/>'; for ($a=0;$a<$num;$a++) { $row = mysqli_fetch_assoc($result); print_r($row); echo '<br/>'; } mysqli_close($db); ?>