码迷,mamicode.com
首页 > 数据库 > 详细

PHP操作数据库

时间:2015-09-28 16:05:45      阅读:261      评论:0      收藏:0      [点我收藏+]

标签:

1.

<?php

/* MySQL

create database foo charset gbk
create database foo charset utf8

*/

$conn = mysql_connect(‘localhost‘,‘root‘,‘‘);

if($conn){
//echo ‘connect success‘;

mysql_select_db(‘myapp‘,$conn);

// $result = mysql_query("SELECT id, name FROM users WHERE id = 1");

// $result_arr = mysql_fetch_assoc($result);

// print_r($result_arr);

// $result_arr = mysql_fetch_assoc($result);

// print_r($result_arr);

// echo ‘data length: ‘.mysql_num_rows($result);

// $data_count = mysql_num_rows($result);
// for($i=0;$i<$data_count;$i++){
// print_r(mysql_fetch_assoc($result));
// }

$result = mysql_query("SELECT COUNT(*) FROM users WHERE name = ‘iwen‘");
if($result){
$result_arr = mysql_fetch_array($result);
echo ‘data length: ‘.$result_arr[0];
}else{
echo ‘query fail‘;
}

}else{
echo ‘connect fail‘;
}

 

PHP操作数据库

标签:

原文地址:http://www.cnblogs.com/htmlphp/p/4844058.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!