4

php5操作mysql数据库


昨天记录了学习mysql数据库,今天接着学习用php来操作mysql数据库.

  1. <?php
  2. error_reporting(0);
  3. $user = "root"; \\设置mysql账号
  4. $pwd  = "yourpassword"; \\账号密码
  5. $host = "localhost";   \\主机
  6. $myDBmysql_connect($host,$user,$pwd) \\主机,用户名,密码
  7.         or die("无法连接数据库!<BR />");
  8.         echo "连接数据库成功!<BR />";
  9. mysql_close($myDB); \\关闭数据库的连接
  10. ?>



好了,保存一下刷新看看,如果没有错误就会显示”连接数据库成功!”
如果失败则出现”无法连接数据库!”
error_reporting(0);
是禁止输出错误。

我猜~这些文章你可能也感兴趣

总共有4个留言:

  1. 诗意地栖息在大地上 on 十二 12th, 2008 - 14:09

    沙发一下,呵呵。


    回复:已经回访啦~

  2. 虫儿 on 十二 12th, 2008 - 14:26

    数据库这东西貌视很难的。我一点儿也不敢动。


    回复:难就学它,以后就不难了…

  3. longlan on 十二 13th, 2008 - 01:28

    地板!学习了,这两天一直在升级各个程序,常碰许多数据库!

  4. CG on 十二 20th, 2008 - 20:24

    禁止显示错误的话可不是好事,你的PM会杀了你的
    可以修改成
    IF(!$_DEBUG) error_reporting(0);
    有时候错误可以帮助你改进程序,敢于挑战白盒才是正真的牛人



    回复:CG教训得是啊..

给我留言:

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word