当前位置: 首页>>代码示例>>PHP>>正文


PHP connection::obj方法代码示例

本文整理汇总了PHP中connection::obj方法的典型用法代码示例。如果您正苦于以下问题:PHP connection::obj方法的具体用法?PHP connection::obj怎么用?PHP connection::obj使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在connection的用法示例。


在下文中一共展示了connection::obj方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: create

 public static function create()
 {
     $connect = new mysqli('localhost', 'root', '');
     // Check connection
     if ($connect->connect_error) {
         die("Connection failed: " . $connect->connect_error);
     }
     // Create database
     $sql = "CREATE DATABASE IF NOT EXISTS Cafeteria_DataBase";
     if ($connect->query($sql) === FALSE) {
         echo "Error creating database: " . $connect->error;
     }
     connection::$obj = mysqli_connect('localhost', 'root', '', 'Cafeteria_DataBase');
     if (mysqli_connect_errno()) {
         echo 'Error: Could not connect to database. Please try again later.';
     }
     ////create table users
     $sq = "CREATE TABLE IF NOT EXISTS Users (uid int unsigned not null auto_increment primary key,name char(50) not null,email char(50) not null,password char(50) not null,profilePicture char(50) not null,EXT char(50) not null,rid int unsigned not null);";
     if (connection::$obj->query($sq) === FALSE) {
         echo "Error creating table: " . connection::$obj->error;
     }
     ////create table products
     $sq = "CREATE TABLE IF NOT EXISTS Products (pid int unsigned not null auto_increment primary key,pname char(50) not null,productPicture char(50) not null,price int not null,available enum('0','1') not null,cid int unsigned not null);";
     if (connection::$obj->query($sq) === FALSE) {
         echo "Error creating table: " . connection::$obj->error;
     }
     ////create table Category
     $sq = "CREATE TABLE IF NOT EXISTS Category (cid int unsigned not null auto_increment primary key,categoryName char(50) not null);";
     if (connection::$obj->query($sq) === FALSE) {
         echo "Error creating table: " . connection::$obj->error;
     }
     ////create table Room
     $sq = "CREATE TABLE IF NOT EXISTS Room (rid int unsigned not null auto_increment primary key,roomNumber int not null);";
     if (connection::$obj->query($sq) === FALSE) {
         echo "Error creating table: " . connection::$obj->error;
     }
     ////////////////////////////////////////////
     ////////////////////--Rooms--///////////////
     for ($i = 2000, $j = 1; $i < 2020; $i += 1, $j++) {
         $query = "insert into Room values({$j},'" . $i . "');";
         mysqli_query(connection::$obj, $query);
     }
     /////////////--adminRecord--////////////
     $query = "insert into Users values(1,'admin','admin123@gmail.com',md5('123'),'admin.jpg','1010',1);";
     mysqli_query(connection::$obj, $query);
     ///////////////////////////////////
     ////////////////////////////////////////////
     ////create table Orders
     $sq = "CREATE TABLE IF NOT EXISTS Orders (oid int unsigned not null auto_increment primary key,uid int unsigned not null,orderDate date not null,amount int not null,status char(50) not null,comment char(100) not null,rid int unsigned not null);";
     if (connection::$obj->query($sq) === FALSE) {
         echo "Error creating table: " . connection::$obj->error;
     }
     /////create table orderProducts
     $sq = "CREATE TABLE IF NOT EXISTS orderProducts (oid int unsigned not null,pid int unsigned not null,numofItems int not null);";
     if (connection::$obj->query($sq) === FALSE) {
         echo "Error creating table: " . connection::$obj->error;
     }
     ///////////////////////////////////////////////////create table change
     $sq = "CREATE TABLE IF NOT EXISTS changes (tableName char(20) not null UNIQUE ,changeDate date not null,serverDate date not null);";
     if (connection::$obj->query($sq) === FALSE) {
         echo "Error creating table: " . connection::$obj->error;
     }
     /////////////--change table data--////////////
     $query = "insert into changes values('Users',NOW(),NOW());";
     mysqli_query(connection::$obj, $query);
     $query = "insert into changes values('Products',NOW(),NOW());";
     mysqli_query(connection::$obj, $query);
     $query = "insert into changes values('Category',NOW(),NOW());";
     mysqli_query(connection::$obj, $query);
     $query = "insert into changes values('Room',NOW(),NOW());";
     mysqli_query(connection::$obj, $query);
     $query = "insert into changes values('Orders',NOW(),NOW());";
     mysqli_query(connection::$obj, $query);
     ///////////////////////create trigger to user////////////***************
     $query = "DELIMITER //\n\t\t\tCREATE TRIGGER changes BEFORE INSERT ON\n\t\t\tUsers FOR EACH ROW BEGIN\n\t\t\t\t\t\tUPDATE changes\n\t\t\tSET changeDate = NOW() where tableName='Users'\n\t\t\tEND //\n\t\t\tDELIMITER ;";
     mysqli_query(connection::$obj, $query);
     ///////////////////////create trigger to products////////////***************
     $query = "DELIMITER //\n\t\t\tCREATE TRIGGER changes BEFORE INSERT ON\n\t\t\tProducts FOR EACH ROW BEGIN\n\t\t\t\t\tUPDATE changes\n\t\t\tSET changeDate = NOW() where tableName='Products'\n\t\t\tEND //\n\t\t\tDELIMITER ;";
     mysqli_query(connection::$obj, $query);
     ///////////////////////create trigger to category////////////***************
     $query = "DELIMITER //\n\t\t\tCREATE TRIGGER changes BEFORE INSERT ON\n\t\t\tCategory FOR EACH ROW BEGIN\n\t\t\t\t\t\tUPDATE changes\n\t\t\tSET changeDate = NOW() where tableName='Category'\n\t\t\tEND //\n\t\t\tDELIMITER ;";
     mysqli_query(connection::$obj, $query);
     ///////////////////////create trigger to Room////////////***************
     $query = "DELIMITER //\n\t\t\tCREATE TRIGGER changes BEFORE INSERT ON\n\t\t\tRoom FOR EACH ROW BEGIN\n\t\t\t\t\t\tUPDATE changes\n\t\t\tSET changeDate = NOW() where tableName='Room'\n\t\t\tEND //\n\t\t\tDELIMITER ;";
     mysqli_query(connection::$obj, $query);
     //////////////////////create trigger to Orders////////////***************
     $query = "DELIMITER //\n\t\t\tCREATE TRIGGER changes BEFORE INSERT ON\n\t\t\tOrders FOR EACH ROW BEGIN\n\t\t\t\t\t\tUPDATE changes\n\t\t\tSET changeDate = NOW() where tableName='Orders'\n\t\t\tEND //\n\t\t\tDELIMITER ;";
     mysqli_query(connection::$obj, $query);
     /////////////////add relationship between tables
     $sq = "alter table Users add foreign key (rid) references Room (rid);";
     connection::$obj->query($sq);
     $sq = "alter table Products add foreign key (cid) references Category (cid);";
     connection::$obj->query($sq);
     $sq = "alter table Orders add foreign key (uid) references Users (uid);";
     connection::$obj->query($sq);
     $sq = "alter table Orders add foreign key (rid) references Room (rid);";
     connection::$obj->query($sq);
     $sq = "alter table orderProducts add foreign key (oid)  references Orders (oid);";
     connection::$obj->query($sq);
     $sq = "alter table orderProducts add foreign key (pid)  references Products (pid);";
//.........这里部分代码省略.........
开发者ID:smagdy,项目名称:PHPproject,代码行数:101,代码来源:connection.php


注:本文中的connection::obj方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。