PHP操作数据库的常用函数
<?php
$con = mysql_connect("localhost", "root", "");
if (!$con) {
die("无法连接数据库:".mysql_error());
}
mysql_query("set names utf8");
mysql_select_db('blog');
function dump($arr){
echo "<pre>";
print_r($arr);
echo "</pre>";
}
function one($sql){
$result = mysql_query($sql);
return mysql_fetch_array($result);
}
function all($sql){
$array = array();
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)){
$array[] = $row;
}
return $array;
}
function num_rows($sql) {
$result = mysql_query($sql);
return mysql_num_rows($result);
}