DB Create and Insert
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$conn = new mysqli($servername, $username, $password);
if($conn -> connect_error){
die("Connectionn failed:" . $conn->connect_error);
}
$sql = "CREATE DATABASE myDB";
if($conn -> query($sql) === TRUE){
echo "Database created successfully";
}else{
echo "Error creating database:" . $conn->error;
}
$sql_table = "CREATE TABLE MyTable(id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
firstname VARCHAR(30) NOT NULL,
lastname VARCHAR(30) NOT NULL,
email VARCHAR(50),
reg_date TIMESTAMP
)";
if($conn->query($sql) === TRUE){
echo "Table MyTable created successfully";
}else{
echo "Error creating table:" . $conn->error;
}
$sql_record = "INSERT INTO MyTable(firstname, lastname, email) VALUES ('J', 'Lam', 'x@xx.com')";
if($conn -> query($sql) === TRUE){
$last_id = $conn -> insert_id;
echo "New record created successfully";
}else{
echo "Error:" . $sql. "<br> . $conn -> error";
}
$sql_multiInsert = "INSERT INTO MyTable(firstname, lastname, email) VALUES ('Jo', 'Do', 'Jo@xx.com')";
$sql_multiInsert .= "INSERT INTO MyTable(firstname, lastname, email) VALUES('Ma', 'Mo', 'Ma@xx.com')";
$sql_multiInsert .= "INSERT INTO MyTable(firstname, lastname, email) VALUES('Ju', 'Do', 'Ju@xx.com')";
if($conn -> multi_query($sql_multiInser) === True){
echo "New records created successfully";
}else{
echo "Error:" .$sql . "<br>" . $conn -> error;
}
$conn -> close();
?>
<?php
$servername = "servername";
$username = "username";
$password = "password";
$conn = mysqli_connect($servername, $username, $password);
if($conn){
die("Connection failed:" . mysqli_connect_error());
}
$sql = "CREATE DATABASE myDB";
if(mysqli_query($conn, $sql)){
$last_id = mysqli_insert_id($conn);
echo "Database created successfully";
}else{
echo "Error creating database:" . mysqli_error($conn);
}
$sql_table = "CREATE TABLE MyTable(id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
firstname VARCHAR(30) NOT NULL,
lastname VARCHAR(30) NOT NULL,
email VARCHAR(50),
reg_date TIMESTAMP
)";
if(mysqli_query($conn, $sql)){
echo "Table MyTable created successfully";
}else{
echo "Error creating table:" . mysqli_error($conn);
}
$sql_record = "INSERT INTO MyTable(firstname, lastname, email) VALUES ('J', 'Lam', 'x@xx.com')";
if(mysqli_query($conn, $sql)){
$last_id = $conn -> lastInsertId();
echo "New record created successfully";
}else{
echo "Error:" . $sql . "<br>" . mysqli_error($conn);
}
$sql_multiInsert = "INSERT INTO MyTable(firstname, lastname, email) VALUES ('Jo', 'Do', 'Jo@xx.com')";
$sql_multiInsert .= "INSERT INTO MyTable(firstname, lastname, email) VALUES('Ma', 'Mo', 'Ma@xx.com')";
$sql_multiInsert .= "INSERT INTO MyTable(firstname, lastname, email) VALUES('Ju', 'Do', 'Ju@xx.com')";
if(mysqli_multi_query($conn, $sql)){
echo "New records created successfully";
}else{
echo "Error:" .$sql . "<br>" . mysqli_error($conn);
}
mysqli_close($conn);
?>
<?php
$servername = "localhost";
$username = "username";
$password = "password"
try{
$conn = new PDO("mysql::host=$servername;dbname=myDB", $username, $password);
$conn -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "CREATE DATABASE myDB";
$conn -> exex($sql);
echo "Database created successfully<br>";
$sql_table = "CREATE TABLE MyTable(id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
firstname VARCHAR(30) NOT NULL,
lastname VARCHAR(30) NOT NULL,
email VARCHAR(50),
reg_date TIMESTAMP
)";
$conn -> exec($sql);
echo "Table MyTable created successfully";
$sql_record = "INSERT INTO MyTable(firstname, lastname, email) VALUES ('J', 'Lam', 'x@xx.com')";
$conn -> exec($sql);
echo "New record created successfully";
$conn -> beginTransaction();
$conn -> exec(INSERT INTO MyTable(firstname, lastname, email) VALUES ('Jo', 'Do', 'Jo@xx.com'));
$conn -> exec(INSERT INTO MyTable(firstname, lastname, email) VALUES('Ma', 'Mo', 'Ma@xx.com'));
$conn -> commit();
echo "New records created successfully";
}catch(PDOException $e){
echo $sql. "<br>" . $e -> getMessage();
}
?>
DB Create and Insert的更多相关文章
- oracle job create table insert into
create or replace procedure proc_tzyj is begin insert into t_trade_activity@dw3_link.regress.rdbms.d ...
- Create,Insert
创建表 create table people ( id int ,name ) ) create table toys ( id int ,name ) ,people_id int ) CREAT ...
- Esper系列(九)NamedWindow语法create、Insert、select
功能:用于存储一种或多种类型的事件的集合,并能对所存储的事件进行增删改查操作. CreateNameWindow 根据已有的数据源构造 格式: 1 [context context_name] 2 ...
- mysql 表格操作指令大全(Show、desc、create、insert into、delete、select、drop、update、alter)
使用数据库 use 数据库名 eg: use weiying 2. 查看库里所有的表 Show tables 3.查看所表的结构 desc 表名 desc score 4.建表create tabl ...
- ORACLE的Copy命令和create table,insert into的比较
在数据表间复制数据是Oracle DBA经常面对的任务之一,Oracle为这一任务提供了多种解决方案,SQL*Plus Copy 命令便是其中之一.SQL*Plus Copy 命令通过SQL*Net在 ...
- 关于rails中 rake db:create 失败的问题
提示信息: rake aborted!Could not find a JavaScript runtime. See https://github.com/sstephenson/execjsfor ...
- jBPM4.4 no jBPM DB schema: no JBPM4_EXECUTION table. Run the create.jbpm.schema target first in the install tool.
jBPM4.4 no jBPM DB schema: no JBPM4_EXECUTION table. Run the create.jbpm.schema target first in the ...
- Golang tool:include spider library,image library and some other db library such as mysql,redis,mogodb,hbase,cassandra
一.Go_tool This is a tool library for Golang.Dont't worry about not understant it! All comment writes ...
- 数据定义: CREATE、DROP、ALTER
CREATE DATABASE 句法 CREATE DATABASE [IF NOT EXISTS] db_name 数据库.表.索引.列和别名 中被给出. 如果数据库已经存在,并且你没有指定 IF ...
随机推荐
- Qt之QLineEdit
简述 QLineEdit是一个单行文本输入框. QLineEdit允许用户输入和编辑单行纯文本,提供了很多有用的编辑功能,包括:撤消和重做.剪切和粘贴.以及拖放(见setDragEnabled()). ...
- Qt之QCustomPlot(图形库)
简述 QCustomPlot是一个基于Qt C++的图形库,用于绘制和数据可视化 - 制作漂亮的2D图 - 曲线图.趋势图.坐标图.柱状图等,并为实时可视化应用程序提供高性能服务.它没有进一步的依赖关 ...
- Asp.net 解析json
Asp.net Json数据解析的一种思路 http://www.cnblogs.com/scy251147/p/3317366.html http://tools.wx6.org/json2csha ...
- ie6 ie7 绝对定位 相对定位 层被遮住
relative 上加上z-index有多个,则z-index递减, absolute层显示则不会被其它标签挡住.
- 六个前端开发工程师必备的Web设计模式/模块资源(转)
[导读] Yahoo的设计模式库Yahoo的设计模式库包含了很多可以帮助开发设计人员解决遇到的问题的资源,包括开发中常常需要处理的导航,互动效果及其布局网格等大家常用的组件和模块响应式设计模式库这个响 ...
- js——全选框 checkbox
一直会碰见input 全选框的问题,先整理一种情况: 1. <input id="selectAll" type="checkbox" />全选 2 ...
- FZU 1911 Construct a Matrix
题目链接:Construct a Matrix 题意:构造一个矩阵,要求矩阵的每行每列的和都不相同.矩阵的边长是前n项斐波那契的和. 思路:由sn = 2*(fn-1)+(fn-2)-1,只要知道第n ...
- 使用AIDL将接口暴露给客户端(远程绑定Service)
import java.util.Timer;import java.util.TimerTask; import jww.mediaprovidertest.ICat.Stub;import and ...
- 关于jquery html()方法获取带有OBJECT标签的元素内容时,出现“类型不匹配。”的解决办法
关于jquery html()方法获取带有OBJECT标签的元素内容时,出现“类型不匹配.”的解决办法 解决办法: $("selector").clone().html()
- struts中的数据校验
1.struts中如何进行数据校验 在每一个Action类中,数据校验一般都写在业务方法中,比如login().register()等.struts提供了数据校验功能.每个继承自ActionSuppo ...