Chinaunix首页 | 论坛 | 博客
  • 博客访问: 926546
  • 博文数量: 146
  • 博客积分: 3321
  • 博客等级: 中校
  • 技术积分: 1523
  • 用 户 组: 普通用户
  • 注册时间: 2008-08-29 10:32
文章分类

全部博文(146)

文章存档

2014年(2)

2013年(5)

2012年(4)

2011年(6)

2010年(30)

2009年(75)

2008年(24)

分类: Mysql/postgreSQL

2009-11-29 18:39:32

lamp环境建立完成之后尝试用php连接mysql数据库。
使用下面的php代码
    printf("hello\n");
    echo "hello world";

    $cn=mysql_connect('localhost','root','boyan')
        or die("不能连接!");
    $strSql="select * from a";
    $result=mysql_db_query("test", $strSql, $cn);

    while ($arr=mysql_fetch_array($result)) {
        printf("%s\n", $arr[sname]);
    }
    mysql_close($cn);
?>
浏览器中显示Call to undefined function: mysql_connect()。
这说明你的php不能和mysql正常连接。这个原因在于:
你少装了一个包。ubuntu下运行
sudo apt-get install php5-mysql
dpkg-reconfigure php5-mysql
sudo /etc/init.d/mysql restart
sudo /etc/init.d/apache2 restart
重新测试,如果不出意外的话应该可以连接数据库了。
阅读(6763) | 评论(0) | 转发(0) |
0

上一篇:搭建LAMP

下一篇:skyeye 安装

给主人留下些什么吧!~~