PHP连接MySQL的脚本片段


记录备用:
<?php
$con = mysql_connect("localhost", "root", "your_passwd");
if (!$con) {
	die("Could not connect: " . mysql_error());
}
$db_selected = mysql_select_db("db_name", $con);
if (!$db_selected) {
	die ("Can't use db_name: " . mysql_error());
}

function mquery($query, $conn, $exit=true) {
	$data = @mysql_query($query, $conn);
	if($data === false && $exit) {
		exit("mquery error:" . mysql_error());
	}
	return $data;
}
function getData($query, $conn) {
	$output = array();
	$result = mquery($query, $conn);
    while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
        $output[] = $row;
    }
	return $output;
}
?>

=EOF=

, ,

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注