GRANT PRIVILEGES ON *.* TO 'chen' IDENTIFIED BY 'PASSWD';
CREATE DATABASE family;
CREATE DATABASE 'family';
mysql> CREATE DATABASE 'family';
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''family'' at line 1
USE family;
INSERT INTO family VALUES (1, 'Zhang San', 1234567);
INSERT INTO family VALUES (2, 'li Si', 7654321);
<html>
<head>
<title>Hi PHP</title>
</head>
<body>
<?php
//MySQL Connect to database
$connection = mysql_connect('localhost', 'chen', 'passwd');
if(!$connection){
die("Could not connect to the database: <br />".mysql_error());
}
else{
echo "Connected successful!<br />";
}
</body>
</html>
<html>
<head>
<title>Hi PHP</title>
</head>
<body>
<?php
//MySQL Connect to database
$connection = mysql_connect('localhost', 'chen', 'passwd');
if(!$connection){
die("Could not connect to the database: <br />".mysql_error());
}
else{
echo "Connected successful!<br />";
}
//MySQL Select database
$db_select = mysql_select_db('family');
if(!$db_select){
die("Select database failed: <br />".mysql_error());
}
else{
echo "Selected store database successful!<br />";
}
//MySQL query
$result = mysql_query('select * from authors');
if(!$result){
die("Query Failed: <br />".mysql_error());
}
else{
echo "query successful!<br />";
}
//MySQL Another way to do the same work
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo "OK<br />";
echo $row[id].",".$row[name].",".$row[phone].'<br />';
}
//MySQL Close connect
mysql_close($connection);
?>
</body>
</html>
<html>
<head>
<title>Hi PHP</title>
</head>
<body>
<?php
//MySQL Connect to database
$connection = mysql_connect('localhost', 'chen', 'passwd');
if(!$connection){
die("Could not connect to the database: <br />".mysql_error());
}
else{
echo "Connected successful!<br />";
}
//MySQL Select database
$db_select = mysql_select_db('family');
if(!$db_select){
die("Select database failed: <br />".mysql_error());
}
else{
echo "Selected store database successful!<br />";
}
//MySQL query
$result = mysql_query('select * from authors');
if(!$result){
die("Query Failed: <br />".mysql_error());
}
else{
echo "query successful!<br />";
}
//MySQL Fetch query results, and show it to user
while($result_row = mysql_fetch_row($result)){
foreach($result_row as $value)
{
echo $value.',';
}
echo '<br />';
}
//MySQL Another way to do the same work
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
echo "OK<br />";
echo $row[id].",".$row[name].",".$row[phone].'<br />';
}
//MySQL Close connect
mysql_close($connection);
?>
</body>
</html>发表于 @ 2008年02月05日 00:43:00 | 评论( loading... ) | 举报| 收藏