欢迎进入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