进行下php MySQL的连接测试,学习mysql_connect的用法。
代码:
<head>
<title>MySQL Connection连接测试-www.</title>
</head>
<body>
<h2>
<?php $connection = mysql_connect( "localhost", "root", "" )
or die( "对不起,未能成功连接至mysql数据库" );
echo( "成功连接至mysql数据库" );
?>
</h2>
</body>
</html>
PHP 5中使用MySQLi扩展的例子。
代码:
<?php
/**
* mysqli扩展示例
* by www.
*/
$mysqli = mysqli_connect("localhost", "root", "","mydatabase", 3306);
$result = mysqli_query($mysqli, "SELECT * FROM mytable");
while($row = mysqli_fetch_array($result)) {
foreach($row as $key => $value) {
echo "$key = $value</BR>\n";
}
}
mysqli_free_result($result);
mysqli_close($mysqli);
?>
php中实现mcrypt加密与解决的例子。
代码:
<?
/**
* mcrypt加密与解密
* by www.
*/
$data = 'data';
$key = "key";
$algorithm = MCRYPT_BLOWFISH;
$mode = MCRYPT_MODE_CBC;
$iv = mcrypt_create_iv(mcrypt_get_iv_size($algorithm,$mode), MCRYPT_DEV_URANDOM);
$encrypted_data = mcrypt_encrypt($algorithm, $key, $data, $mode, $iv);
$decrypted_data = mcrypt_decrypt($algorithm, $key, $encrypted_data, $mode, $iv);
print "解密数据为:$decrypted_data";
?>