资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

php内数据库该怎么写 php的数据库在哪个目录下

PHP中写一个数据库查询的类的方法代码要如何写

?php

成都创新互联公司是一家集网站建设,北海街道企业网站建设,北海街道品牌网站建设,网站定制,北海街道网站建设报价,网络营销,网络优化,北海街道网站推广为一体的创新建站企业,帮助传统企业提升企业形象加强企业竞争力。可充分满足这一群体相比中小企业更为丰富、高端、多元的互联网需求。同时我们时刻保持专业、时尚、前沿,时刻以成就客户成长自我,坚持不断学习、思考、沉淀、净化自己,让我们为更多的企业打造出实用型网站。

if(!defined("INCLUDE_MYSQL_OK")) {

define("INCLUDE_MYSQL_OK","");

class MySQL_class {

var $debug = true;

var $db,

$id,

$result, /* 查询结果指针 */

$rows, /* 查询结果行数 */

$fields, /* 查询结果列数 */

$data, /* 数据结果 */

$arows, /* 发生作用的纪录行数目 */

$iid; /* 上次插入操作后,可能存在的"AUTO_INCREMENT"属性字段的值,如果为"0",则为空 */

var $user, $pass, $host, $charset;

/*

* 请注意用户名和密码是否正确

*/

function Setup ($host, $user, $pass, $charset='utf8') {

$this-host = $host;

$this-user = $user;

$this-pass = $pass;

$this-charset = $charset;

}

function Connect ($db = "") {

global $CFG_MYSQL_INFO;

if (!$this-host) {

$this-host = $CFG_MYSQL_INFO["host"];

}

if (!$this-user) {

$this-user = $CFG_MYSQL_INFO["user"]; /* 在这里作修改 */

}

if (!$this-pass) {

$this-pass = $CFG_MYSQL_INFO["passwd"]; /* 在这里作修改 */

}

if (!$this-charset) {

$this-charset = "utf8"; /* 在这里作修改 */

}

if (empty($db))

$this-db = $CFG_MYSQL_INFO["database"];

else

$this-db = $db;

$this-id = @mysql_connect($this-host, $this-user, $this-pass);

if (!$this-id)

return false;

$this-SelectDB($this-db); /* 定位到指定数据库 */

$this-Query("SET NAMES '".$this-charset."'");

return true;

}

function Close(){

@mysql_close($this-id);

}

function SelectDB ($db) {

if(!@mysql_select_db($db, $this-id))

return false;

else

return true;

}

function Begin () {

$this-result = @mysql_query("START TRANSACTION WITH CONSISTENT SNAPSHOT", $this-id);

if (!$this-result)

return false;

return true;

}

function Commit () {

$this-result = @mysql_query("COMMIT", $this-id);

if (!$this-result)

return false;

return true;

}

function Rollback () {

$this-result = @mysql_query("ROLLBACK", $this-id);

if (!$this-result)

return false;

return true;

}

function Escape ($str) {

$escstr = mysql_escape_string($str);

return $escstr;

}

# 普通查询功能,主要用于返回结果是多条记录的情况

# 请使用 Fetch 方法取得每条记录信息

function Query ($query) {

$this-result = @mysql_query($query, $this-id);

if (!$this-result)

{

if ($this-debug)

MySQL_ErrorMsg ("不能执行查询(query): $query");

else

return false;

}

$this-rows = @mysql_num_rows($this-result);

$this-fields = @mysql_num_fields($this-result);

if (!$this-rows) return false;

return true;

}

function QuerySql ($query) {

$ret = @mysql_query($query, $this-id);

if ($ret === false)

{

if ($this-debug)

MySQL_ErrorMsg ("不能执行查询(query): $query");

else

return false;

}

$this-result = $ret;

$this-rows = @mysql_num_rows($this-result);

$this-fields = @mysql_num_fields($this-result);

return true;

}

# 如果查询结果为单条记录时使用,返回结果存储于数组 data 中

function QueryRow ($query) {

$this-result = @mysql_query($query, $this-id);

if (!$this-result)

{

if ($this-debug)

MySQL_ErrorMsg ("不能执行查询(query): $query");

else

return false;

}

$this-rows = @mysql_num_rows($this-result);

$this-data = @mysql_fetch_array($this-result, MYSQL_ASSOC);

//MySQL_ErrorMsg ("不能从查询结果中取得数据 $query");

if (!$this-result || !$this-rows)

return false;

return true;

}

# 移动到指定记录行,将该行结果储存于数组 data 中

function Fetch ($row) {

if(!@mysql_data_seek($this-result, $row))

//MySQL_ErrorMsg ("不能定位到指定数据行 $row");

return false;

$this-data = @mysql_fetch_array($this-result, MYSQL_ASSOC);

//MySQL_ErrorMsg ("不能提取指定数据行数据 $row");

if (!$this-data)

return false;

return true;

}

/* 以下方法将作用于 arows */

/* 此方法将作用于 iid */

function Insert ($query) {

$this-result = @mysql_query($query, $this-id);

if (!$this-result)

{

if ($this-debug)

MySQL_ErrorMsg ("不能执行查询(query): $query");

else

return false;

}

$this-arows = @mysql_affected_rows($this-id);

$this-iid = @mysql_insert_id($this-id);

return true;

}

function Update ($query) {

$this-result = @mysql_query($query, $this-id);

if (!$this-result)

{

if ($this-debug)

MySQL_ErrorMsg ("不能执行查询(query): $query");

else

return false;

}

$this-arows = @mysql_affected_rows($this-id);

if (!$this-arows || $this-arows == -1)

return false;

return true;

}

function Delete ($query) {

$this-result = @mysql_query($query, $this-id);

if (!$this-result)

{

if ($this-debug)

MySQL_ErrorMsg ("不能执行查询(query): $query");

else

return false;

}

$this-arows = @mysql_affected_rows($this-id);

return true;

}

function Error (){

return mysql_error()."(".mysql_errno().")";

}

function Errno (){

return mysql_errno();

}

}

/*

* MySQL_ErrorMsg

* 输出错误信息

*/

function MySQL_ErrorMsg ($msg) {

# 关闭可能影响字符显示的HTML代码

echo("/ul/dl/ol\n");

echo("/table/script\n");

# 错误信息

$text = "font color=\"#000000\" style=\"font-size: 9pt; line-height: 12pt\"p系统提示:".$msg."br";

$text .= "错误信息:";

$text .= mysql_error()."br";

$text .= "错误代码:".mysql_errno()."brbr";

$text .= "请稍候再试,如果问题仍然存在,请与 a href=\"mailto:wuqiong@igenus.org\"系统管理员/a 联系!";

$text .= "/font\n";

die($text);

}

}

?

一些细节的地方自己修改吧 主要是我在别的文件专门定义了全局变量,你看一遍,把应改的地方改一下就好了

php写入数据库

PHP向MySQL数据库中写入数据有三个步骤:

1,PHP和MySQL建立连接关系

2,打开MySQL数据库

3,接受页面数据,PHP录入到指定的表中

1、2两步可直接使用一个数据库链接文件即可:conn.php

代码如下

?php

mysql_connect("localhost","root","");//连接MySQL

mysql_select_db("hello");//选择数据库

?

当然,前提是已经安装WEB服务器、PHP和MySQL,并且建立MySQL表“cnbruce”

mysql_connect()中三个参数分别为MySQL地址、MySQL用户名和MySQL密码

然后就是通过WEB页面传递数据,让PHP通过SQL语句将数据写入MySQL数据库指定的表中,比如新建文件 post.php

代码如下

?php

require_once("conn.php");//引用数据库链接文件

$uname = $_GET['n'];//GET方法为URL参数传递

$psw = $_GET['p'];

$psw=md5($psw);//直接使用MD5加密

$sql = "insert into members(username,password) values ('$uname','$psw')";

mysql_query($sql);//借SQL语句插入数据

mysql_close();//关闭MySQL连接

echo "成功录入数据";

?

测试页面: ;p=i0514

即可向MySQL数据库hello的members表中插入新的数据“cnbruce”到username字段、“i0514”到password字段

补充:读取表

读取表中的内容,这里我们用while,可以根据具体情况,用for 或其他的.

代码如下

while($row = mysql_fetch_array($result))

{

echo "div style="height:24px; line-height:24px; font-weight:bold;""; //排版代码

echo $row['Topic'] . "br/";

echo "/div"; //排版代码

php如何写入数据库

数组吧,直接把数组转字符串啊

implode() 函数返回由数组元素组合成的字符串。(适合一维数组)

$arr = array('Hello', 'World', 'I', 'love', 'Shanghai');

1 echo implode(" ",$arr);//加空格

the result : Hello World I love Shanghai

2 echo implode(",",$arr);//加逗号

the result : Hello,World,I,love,Shanghai

转换数组为字符串后插入数据库就可以了。

PHP网站安装数据库怎么填写

安装网站程序时,数据库资料怎么填?

举例说明:你的数据库名称是:zp7023_db,

密码是:r4b3218e5

,数据库地址:bdm-008.hichina点抗 ,

则填写样式如下:

系统默认主机名为:bdm-008.hichina点抗

sql:数据库名称:

zp7023_db

sql:数据库用户名:

zp7023

sql:数据库密码:

r4b3218e5

数据库地址:bdm-008.hichina点抗


分享名称:php内数据库该怎么写 php的数据库在哪个目录下
分享路径:http://cdkjz.cn/article/ddcppcd.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220