资讯

精准传达 • 有效沟通

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

PHP选择当前数据库失败 选择当前数据库的命令是

php连接数据库的类,但是选择数据库的时候总是出错,怎么回事呢?

构造函数错咯

创新互联建站于2013年创立,是专业互联网技术服务公司,拥有项目网站建设、成都做网站网站策划,项目实施与项目整合能力。我们以让每一个梦想脱颖而出为使命,1280元钦州做网站,已为上家服务,为钦州各地企业和个人服务,联系电话:13518219792

function __construct($host,$user,$pass,$database){

$this - host=$host;

$this - user=$user;

$this - pass=$pass;

$this - database=$database;

// echo $db;

$conn = mysql_connect($host,$user,$pass);

$db = mysql_select_db($this - database,$conn);

if($db){

echo "数据库成功";

}else{

echo "数据库失败";

}

}

//给你改咯哈这个类

class register{

private $host;        //The host address

private $user;        //The user

private $pass;    //The password

private $database;          //The database

private $conn;

//Connect with the database

function __construct($host,$user,$pass,$database){

$this - host=$host;

$this - user=$user;

$this - pass=$pass;

$this - database=$database;          

$conn = mysql_connect($host,$user,$pass)or die("连接失败!");

mysql_select_db($this - database,$conn) or die("选择数据库失败!");

$this-conn=$conn;

}

//Add a user

function addUser($data){

$dataObj    =     $data;//类里边不要把变量写得太死

$userInfo   =     json_decode($dataObj,true);  //change the data from the type of json to array.

$username   =     $userInfo[0];

$password   =     $userInfo[1];

$repassword =     $userInfo[2];

//The sql to add the new user

@$sql_addUser = EOF

insert into users values("","$username","$password","$repassword");

EOF;

// var_dump($sql_addUser);break;

$result = mysql_query($sql_addUser,$this-conn);//指定连接,少些麻烦

// var_dump($result);break;

if($result){

echo  1;

}else{

echo 0;

}

}

}

php数据库选择数据库时出错了

错误描叙清楚

$sql="select * from xh_article";

$res=mysql_query($sql);

echo $res;

----

echo 肯定不行了 var_dump

echo 只能输出 字符串 数字 之类的 不能输出数组 对象

PHP选择数据库失败

亲!你把127.0.0.1换成 localhost, 然后在看一下行否!如果换不行的话可能是你的Apache没有开启! 你可以到这个网站上看一下PHP数据库的连接! 希望能够帮到你!


文章题目:PHP选择当前数据库失败 选择当前数据库的命令是
网页地址:http://cdkjz.cn/article/ddgochi.html
多年建站经验

多一份参考,总有益处

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

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

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