首页 »PHP教程 » mysql创建数据库:如何用PHP和mysql创建一个ShoutBox »正文
mysql创建数据库:如何用PHP和mysql创建一个ShoutBox
来源: 发布时间:星期一, 2009年1月12日 浏览:80次 评论:0
作为 个PHP开发人员 我有时被要求作个shoutbox 如果同样 事情也发生在你身上 这里有 个快速指南 显然 您要为它添加您自己 CSS在上面 但这里是基本思路 我们需要 个MySQL数据库表和 3个PHP文件 首先 我们需要 个文件保存数据库信息 --- 文件 #1:mysql.inc.php--- <?php # Simply Shouting - ashoutboxexample # File name:mysql.inc.php # Description: A file to hold database info. $host ='localhost'; $user ='database_user_name'; $password='database_user_password'; $name ='database_name'; ?> 创建 个有 4个字段 数据表. 我们命名为shouts. 此前可能你没有这个SQL文件, 创建 个PHP文件" .php". 这个文件用过 次的后 记得要删除它! -- 文件 #2: .php-- <?php # Simply Shouting - ashoutboxexample # File name: .php # Description: Creates the database table. // the database info file ("mysql.inc.php"); //连接数据库 $connection= @mysql_connect($host,$user,$password) or die(mysql_error); $db= @mysql_select_db($name,$connection) or die(mysql_error); //如果我们已经有个表名字叫做"shouts", 需要先删除它 $sql='DROP TABLE IF EXISTS `shouts`'; $result= @mysql_query($sql,$connection) or die(mysql_error); // 现在确定没有相同名字表, 创建它 $sql='CREATE TABLE `shouts` ( `id` (11) NOT NULL auto_increment, `timestamp` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, `shoutby` varchar(50) default NULL, `shout` varchar(50) default NULL, PRIMARY KEY `id` (`id`) ) TYPE=MyISAM AUTO_INCREMENT=1'; echo'Creating table: 'shouts'....'; // 关闭连接 $result= @mysql_query($sql,$connection) or die(mysql_error);?> <html> <head> <title>Simply Shouting - 安装</title> </head> <body> <br /> 你安装过程已经完成. 请立即从你服务器上删除所有安装文件. 本包含以下安装文件:<br /> <br /> 1) .php<br /> <br /> <br /> <!-- I could just send them to index.phpautomatically, but then they'd wonder it created correctly or not. --> 点击 <athis.value=''" value="Click & Shout!" size="24" maxlength="50" /> <br><br><input id="submit" name="submit" type="submit" value="Shout!" /></form> </div> </body> </html>
最后, 我们需要 个 PHP 文件处理表单. -- 文件#4: shout.php-- <? # Simply Shouting - ashoutboxexample # File name: shout.php # Description: Process the HTML form _disibledevent="window.open('index.php','_self')"> </body> </html>
相关文章
读者评论
发表评论
|
|