您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

PHP学习笔记:mysql

2024/3/21 4:35:18发布27次查看
欢迎进入linux社区论坛,与200万技术人员互动交流 >>进入 php连接和mysql的交互非常非常方便,api接口也和mysql 的c api非常相似测试:新建一个mysql表数据库phpmyadmin建表语句:view plain create table if not exists `student` (`id` int(11) not nul
欢迎进入linux社区论坛,与200万技术人员互动交流 >>进入
php连接和mysql的交互非常非常方便,api接口也和mysql 的c api非常相似测试:新建一个mysql表数据库phpmyadmin建表语句:view plain create table if not exists `student` (`id` int(11) not null,`name` varchar(60) not null,`age` int(11) not null,primary key (`id`)) engine=myisam default charset=latin1;使用参数 作为输入insert:view plain
{ die('connect failed: ' . mysql_error());}
mysql_select_db(phpmyadmin, $con);
if(!mysql_query(insert into student values($argv[1], '$argv[2]', $argv[3])))
{ die('insert error: ' . mysql_error());} else { echo insert success;}
mysql_close($con);?>
使用参数作为输入select:view plain
{ die('connect failed: ' . mysql_error());}
mysql_select_db(phpmyadmin, $con);
$result = mysql_query(select * from student where id = $argv[1]);
while($row = mysql_fetch_array($result))
{ echo name: . $row['name'] . \n;echo id: . $row['age'] ;echo \n;}
mysql_close($con);?>
测试:view plain $ php insert_test.php 1 peter 20 insert success $ php insert_test.php 2 lucy 30 insert success $ php select_test.php 1 name: peter id: 20 $ php select_test.php 2 name: lucy id: 3
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product