php如何创建数据库 php如何创建数据库constructiondb

如何用php创建mysql数据库

使用EclipsePHP Studio 3 创建一个PHP工程名称为test1,在工程名下面userinfo的文件夹,然后在文件夹创建一个PHP文件(userinfo_create.php):

兴化网站制作公司哪家好,找创新互联!从网页设计、网站建设、微信开发、APP开发、自适应网站建设等网站项目制作,到程序开发,运营维护。创新互联自2013年创立以来到现在10年的时间,我们拥有了丰富的建站经验和运维经验,来保证我们的工作的顺利进行。专注于网站建设就选创新互联

2

打开我们创建PHP文件:

先设置 地址,账号,密码:

$url = "127.0.0.1";//连接数据库的地址

$user = "root"; //账号

$password = "root";//密码

//获取连接$con = mysql_connect($url,$user,$password);

if(!$con){

die("连接失败".mysql_error());

}

3

设置具体连接的数据,那我们这儿连接test数据库,我们通过Navicat 打开mysql 数据库

mysql_select_db("test");

phpstudy怎么创建数据库

phpstudy数据库创建步骤:

1、点击打开phpstudy软件,然后点击mySQL管理器;

2、进入到PHPmyadmin登陆界面,默认账号和密码都是root;

3、登陆进去后,如图所示样式;

4、然后,点击数据库,输入想要的数据名称,如:new,这个随便取;

5、点击创建后,成功后,如图所示;

如何实现PHP自动创建数据库

你做好程序以后,把数据库导出成sql文件

1、连接数据库

2、读取这个sql文件里的sql语句,并执行

3、生成一个数据库连接参数的php文件

?php

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

if (!$con)

{

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

}

if (mysql_query("CREATE DATABASE my_db",$con))

{

echo "Database created";

}

else

{

echo "Error creating database: " . mysql_error();

}

mysql_close($con);

?

?php

class ReadSql {

//数据库连接

protected $connect = null;

//数据库对象

protected $db = null;

//sql文件

public $sqlFile = "";

//sql语句集

public $sqlArr = array();

public function __construct($host, $user, $pw, $db_name) {

$host = empty($host) ? C("DB_HOST") : $host;

$user = empty($user) ? C("DB_USER") : $user;

$pw = empty($pw) ? C("DB_PWD") : $pw;

$db_name = empty($db_name) ? C("DB_NAME") : $db_name;

//连接数据库

$this-connect = mysql_connect($host, $user, $pw) or die("Could not connect: " . mysql_error());

$this-db = mysql_select_db($db_name, $this-connect) or die("Yon can not select the table:" . mysql_error());

}

//导入sql文件

public function Import($url) {

$this-sqlFile = file_get_contents($url);

if (!$this-sqlFile) {

exit("打开文件错误");

} else {

$this-GetSqlArr();

if ($this-Runsql()) {

return true;

}

}

}

//获取sql语句数组

public function GetSqlArr() {

//去除注释

$str = $this-sqlFile;

$str = preg_replace('/--.*/i', '', $str);

$str = preg_replace('/\/\*.*\*\/(\;)?/i', '', $str);

//去除空格 创建数组

$str = explode(";\n", $str);

foreach ($str as $v) {

$v = trim($v);

if (empty($v)) {

continue;

} else {

$this-sqlArr[] = $v;

}

}

}

//执行sql文件

public function RunSql() {

foreach ($this-sqlArr as $k = $v) {

if (!mysql_query($v)) {

exit("sql语句错误:第" . $k . "行" . mysql_error());

}

}

return true;

}

}

//范例:

header("Content-type:text/html;charset=utf-8");

$sql = new ReadSql("localhost", "root", "", "log_db");

$rst = $sql-Import("./log_db.sql");

if ($rst) {

echo "Success!";

}

?


新闻标题:php如何创建数据库 php如何创建数据库constructiondb
URL网址:http://lszwz.com/article/ddioejh.html

其他资讯

售后响应及时

7×24小时客服热线

数据备份

更安全、更高效、更稳定

价格公道精准

项目经理精准报价不弄虚作假

合作无风险

重合同讲信誉,无效全额退款