新网创想网站建设,新征程启航

为企业提供网站建设、域名注册、服务器等服务

php访问数据库代码运行 php怎么操作数据库

php登录页面完整代码连接数据库

创建conn.php,连接数据库。

十载的尖山网站建设经验,针对设计、前端、开发、售后、文案、推广等六对一服务,响应快,48小时及时工作处理。全网营销推广的优势是能够根据用户设备显示端的尺寸不同,自动调整尖山建站的显示方式,使网站能够适用不同显示终端,在浏览器中调整网站的宽度,无论在任何一种浏览器上浏览网站,都能展现优雅布局与设计,从而大程度地提升浏览体验。创新互联公司从事“尖山网站设计”,“尖山网站推广”以来,每个客户项目都认真落实执行。

$dns = 'mysql:host=127.0.0.1;dbname=test';

$username = 'root';

$password = 'root';

// 1.连接数据库,创建PDO对象

$pdo = new PDO($dns,$username,$password);

创建login.html,登陆页面。

用户名

密 码

创建login.php,验证账号密码。

header("Content-Type: text/html; charset=utf8");

if(!isset($_POST["submit"])){

exit("错误执行");

}//检测是否有submit操作

include('conn.php');//链接数据库

$name = $_POST['name'];//post获得用户名表单值

$pwd = sha1($_POST['password']);//post获得用户密码单值

if ($name $pwd){//如果用户名和密码都不为空

$sql = "select * from user where username = '$name' and password='$pwd'";//检测数据库是否有对应的username和password的sql

$stmt = $pdo-prepare($sql);

$stmt-execute();

if($stmt-fetch(PDO::FETCH_BOUND)){//0 false 1 true

header("refresh:0;url=welcome.html");//如果成功跳转至welcome.html页面

exit;

}else{

echo "用户名或密码错误";

echo "

setTimeout(function(){window.location.href='login.html';},1000);

";//如果错误使用js 1秒后跳转到登录页面重试;

}

}else{//如果用户名或密码有空

echo "表单填写不完整";

echo "

setTimeout(function(){window.location.href='login.html';},1000);

";

//如果错误使用js 1秒后跳转到登录页面重试;

}

$pdo = null;

创建signup.html,注册页面

用户名:

密 码:

创建signup.php

header("Content-Type: text/html; charset=utf8");

if(!isset($_POST['submit'])){

exit("错误执行");

}//判断是否有submit操作

$name=$_POST['name'];//post获取表单里的name

$pwd = sha1($_POST['password']);//post获取表单里的password

include('conn.php');//链接数据库

$sql="insert into user(id,username,password) values (null,'$name','$pwd')";//向数据库插入表单传来的值的sql

$stmt = $pdo-prepare($sql);

$stmt-execute();

$stmt-fetch(PDO::FETCH_BOUND);

if (!$stmt){

die('Error: ' . $stmt-getMessage());//如果sql执行失败输出错误

}else{

echo "注册成功";//成功输出注册成功

}

$pdo = null;//关闭数据库

php从数据库里读出的HTML代码然后执行怎么实现

?php require_once("mysql_class.php");

require_once("sys_conf.inc");

header('Content-Type:text/html;Charset=GBK;');

$link_id=mysql_connect($DBHOST,$DBUSER,$DBPWD);

mysql_select_db($DBNAME); //选择数据库my_chat

$sql="SELECT * FROM `dx_leibie`";

$query = mysql_query($sql);

while($row=mysql_fetch_array($query)){

//print_r($row); //$con=array(array('新闻标题','新闻内容'),array('新闻标题2','新闻内容2')); $title=$row[id_lang];

$content=$row[name];

if(!is_dir("up")) //如果此文件夹不存在,则自动建立一个

{

mkdir("up");

}$up="up/";

echo $path=$up.$row[id_lang].'.htm';

$fp=fopen("tmp.htm","r"); //只读打开模板

$str=fread($fp,filesize("tmp.htm"));//读取模板中内容

$str=str_replace("{title}",$title,$str);

echo $str=str_replace("{content}",$content,$str);//替换内容

fclose($fp); $handle=fopen($path,"w"); //写入方式打开新闻路径

fwrite($handle,$str); //把刚才替换的内容写进生成的HTML文件

fclose($handle);

//echo "生成成功";

} // unlink($path); //删除文件

??php require_once("mysql_class.php");

require_once("sys_conf.inc");

header('Content-Type:text/html;Charset=GBK;');

$link_id=mysql_connect($DBHOST,$DBUSER,$DBPWD);

mysql_select_db($DBNAME); //选择数据库my_chat

$sql="SELECT * FROM `dx_leibie`";

$query = mysql_query($sql);

while($row=mysql_fetch_array($query)){

//print_r($row); //$con=array(array('新闻标题','新闻内容'),array('新闻标题2','新闻内容2')); $title=$row[id_lang];

$content=$row[name];

if(!is_dir("up")) //如果此文件夹不存在,则自动建立一个

{

mkdir("up");

}$up="up/";

echo $path=$up.$row[id_lang].'.htm';

$fp=fopen("tmp.htm","r"); //只读打开模板

$str=fread($fp,filesize("tmp.htm"));//读取模板中内容

$str=str_replace("{title}",$title,$str);

echo $str=str_replace("{content}",$content,$str);//替换内容

fclose($fp); $handle=fopen($path,"w"); //写入方式打开新闻路径

fwrite($handle,$str); //把刚才替换的内容写进生成的HTML文件

fclose($handle);

//echo "生成成功";

} // unlink($path); //删除文件

??php require_once("mysql_class.php");

require_once("sys_conf.inc");

header('Content-Type:text/html;Charset=GBK;');

$link_id=mysql_connect($DBHOST,$DBUSER,$DBPWD);

mysql_select_db($DBNAME); //选择数据库my_chat

$sql="SELECT * FROM `dx_leibie`";

$query = mysql_query($sql);

while($row=mysql_fetch_array($query)){

//print_r($row); //$con=array(array('新闻标题','新闻内容'),array('新闻标题2','新闻内容2')); $title=$row[id_lang];

$content=$row[name];

if(!is_dir("up")) //如果此文件夹不存在,则自动建立一个

{

mkdir("up");

}$up="up/";

echo $path=$up.$row[id_lang].'.htm';

$fp=fopen("tmp.htm","r"); //只读打开模板

$str=fread($fp,filesize("tmp.htm"));//读取模板中内容

$str=str_replace("{title}",$title,$str);

echo $str=str_replace("{content}",$content,$str);//替换内容

fclose($fp); $handle=fopen($path,"w"); //写入方式打开新闻路径

fwrite($handle,$str); //把刚才替换的内容写进生成的HTML文件

fclose($handle);

//echo "生成成功";

} // unlink($path); //删除文件

? 用以上先生成一个HTML文件,然后再用require_once("aaa.html");引进来就OK

Ajax怎么调用后台php代码访问数据库并显示

由 JavaScript 调用的服务器页面,是名为 "getuser.php" 的简单 PHP 文件。

该页面用 PHP 编写,并使用 MySQL 数据库。

其中的代码执行针对数据库的 SQL 查询,并以 HTML 表格返回结果:

?php

$q=$_GET["q"];

$con = mysql_connect('localhost', 'peter', 'abc123');

if (!$con)

{

die('Could not connect: ' . mysql_error());

}

mysql_select_db("ajax_demo", $con);

$sql="SELECT * FROM user WHERE id = '".$q."'";

$result = mysql_query($sql);

echo "table border='1'

tr

thFirstname/th

thLastname/th

thAge/th

thHometown/th

thJob/th

/tr";

while($row = mysql_fetch_array($result))

{

echo "tr";

echo "td" . $row['FirstName'] . "/td";

echo "td" . $row['LastName'] . "/td";

echo "td" . $row['Age'] . "/td";

echo "td" . $row['Hometown'] . "/td";

echo "td" . $row['Job'] . "/td";

echo "/tr";

}

echo "/table";

mysql_close($con);

?

例子解释:

当查询从 JavaScript 被发送到这个 PHP 页面,会发生:

PHP 打开到达 MySQL 服务器的连接

找到拥有指定姓名的 "user"

创建表格,插入数据,然后将其发送到 "txtHint" 占位符

php连接access数据库代码

php教程

连接access数据库教程代码

下面提供三种php连接access数据库方法,一种是利用php的pdo,一种是odbc,com接口来与access数据库连接哦。

*/

//利用pdo与access数据库连接

$path

="f:font";

$conn

=

new

pdo("sqlite:$path");

if(

$conn

)

{

echo

('connection

pdo

success');

}

else

{

echo

('cnnection

pdo

fail

,plase

check

database

server!');

}

//利用

odbc_connect连接数据库

$conn

=

odbc_connect("dbdsn","admin","123");

//连接数据源

$doquery=odbc_exec($conn,"select

*

from

表名

where

条件");//执行查询

//利用com接口连接access数据库

$conn=new

com("adodb.connection");

$dsn="driver={microsoft

access

driver

(*.mdb)};dbq=".realpath("path/db1.mdb");

$conn-open($dsn);

php连接数据库代码

根据你贴出来的意思是没有定义这个函数mysql_pconnect()

估计你是调用了一个mysql操作类的程序来操作数据库,

第一,看看你的mysql_pconnect函数名称是否写错

第二,如果是调用了类里面的函数,看看你有没有重新创建类

例如:$doc

=

new

DB_Doc_Read();//new

一个类

$doc-mysql_pconnect();//调用类中的函数

第三,如果没有调用类,是直接写的函数,那应该是mysql_connect函数

图片验证码一般跟你的系统没有关系,因为是显示在客户端的,把你代码贴出来我看看。

PHP访问MYSQL数据库封装类(附函数说明)

复制代码

代码如下:

?php

/*

MYSQL

数据库访问封装类

MYSQL

数据访问方式,php4支持以mysql_开头的过程访问方式,php5开始支持以mysqli_开头的过程和mysqli面向对象

访问方式,本封装类以mysql_封装

数据访问的一般流程:

1,连接数据库

mysql_connect

or

mysql_pconnect

2,选择数据库

mysql_select_db

3,执行SQL查询

mysql_query

4,处理返回的数据

mysql_fetch_array

mysql_num_rows

mysql_fetch_assoc

mysql_fetch_row

etc

*/

class

db_mysql

{

var

$querynum

=

;

//当前页面进程查询数据库的次数

var

$dblink

;

//数据库连接资源

//链接数据库

function

connect($dbhost,$dbuser,$dbpw,$dbname='',$dbcharset='utf-8',$pconnect=0

,

$halt=true)

{

$func

=

empty($pconnect)

?

'mysql_connect'

:

'mysql_pconnect'

;

$this-dblink

=

@$func($dbhost,$dbuser,$dbpw)

;

if

($halt

!$this-dblink)

{

$this-halt("无法链接数据库!");

}

//设置查询字符集

mysql_query("SET

character_set_connection={$dbcharset},character_set_results={$dbcharset},character_set_client=binary",$this-dblink)

;

//选择数据库

$dbname

@mysql_select_db($dbname,$this-dblink)

;

}

//选择数据库

function

select_db($dbname)

{

return

mysql_select_db($dbname,$this-dblink);

}

//执行SQL查询

function

query($sql)

{

$this-querynum++

;

return

mysql_query($sql,$this-dblink)

;

}

//返回最近一次与连接句柄关联的INSERT,UPDATE

或DELETE

查询所影响的记录行数

function

affected_rows()

{

return

mysql_affected_rows($this-dblink)

;

}

//取得结果集中行的数目,只对select查询的结果集有效

function

num_rows($result)

{

return

mysql_num_rows($result)

;

}

//获得单格的查询结果

function

result($result,$row=0)

{

return

mysql_result($result,$row)

;

}

//取得上一步

INSERT

操作产生的

ID,只对表有AUTO_INCREMENT

ID的操作有效

function

insert_id()

{

return

($id

=

mysql_insert_id($this-dblink))

=

?

$id

:

$this-result($this-query("SELECT

last_insert_id()"),

0);

}

//从结果集提取当前行,以数字为key表示的关联数组形式返回

function

fetch_row($result)

{

return

mysql_fetch_row($result)

;

}

//从结果集提取当前行,以字段名为key表示的关联数组形式返回

function

fetch_assoc($result)

{

return

mysql_fetch_assoc($result);

}

//从结果集提取当前行,以字段名和数字为key表示的关联数组形式返回

function

fetch_array($result)

{

return

mysql_fetch_array($result);

}

//关闭链接

function

close()

{

return

mysql_close($this-dblink)

;

}

//输出简单的错误html提示信息并终止程序

function

halt($msg)

{

$message

=

"html\nhead\n"

;

$message

.=

"meta

content='text/html;charset=gb2312'\n"

;

$message

.=

"/head\n"

;

$message

.=

"body\n"

;

$message

.=

"数据库出错:".htmlspecialchars($msg)."\n"

;

$message

.=

"/body\n"

;

$message

.=

"/html"

;

echo

$message

;

exit

;

}

}

?


新闻标题:php访问数据库代码运行 php怎么操作数据库
地址分享:http://www.wjwzjz.com/article/hisoej.html
在线咨询
服务热线
服务热线:028-86922220
TOP