Home > Backend Development > PHP Tutorial > PHP连接局域网MYSQL数据库的简单实例_PHP

PHP连接局域网MYSQL数据库的简单实例_PHP

WBOY
Release: 2016-06-01 12:03:44
Original
925 people have browsed it

复制代码 代码如下:
   $conn=mysql_connect('192.168.0.220','root','123');
    if(!$conn) echo "失败!";
    else echo "成功!";

     // 从表中提取信息的sql语句
    $sql="SELECT * FROM user where userName='$user_name'";
    // 执行sql查询
    $result=mysql_db_query('info', $sql, $conn);
    // 获取查询结果
    $row=mysql_fetch_row($result);
     mysql_close();        

第一行ip对应局域网某台主机,关于局域网内mysql连接可参考我的摘抄。

第六行$user_name是前台传递的参数,组成条件查询,这里用了双引号变量转换。

从jsp到php,无论哪一种,与数据库连接有关的步骤大致就是:

“主机,用户名,密码”得到连接、“数据库,sql,连接”得到结果,最后是结果的处理显示。当然,数据库连接是扩展库为我们完成的,我们能做的仅仅是处理结果而已。

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template