PHP操作MySQL数据库
第一步:连接数据库
$dbhost = 'localhost:3306'; //mysql服务器主机地址
$dbuser = 'guest'; //mysql用户名
$dbpass = 'guest123';//mysql用户名密码
$conn = mysql_connect($dbhost, $dbuser, $dbpass);
if(! $conn ) { die('Could not connect: ' . mysql_error()); }
echo 'Connected successfully';
第二步:选择数据库
mysql_select_db( 'RUNOOB' );
第三步:进行数据库操作
$sql = "INSERT INTO runoob_tbl ". "(runoob_title,runoob_author, submission_date) ". "VALUES ". "('$runoob_title','$runoob_author','$submission_date')"; mysql_select_db('RUNOOB');
mysql_query( $sql, $connection );
更多PHP数据库操作见php.net.