How else can database be created?

Are we only allowed to create a database within phpmyadmin? Can’t we create a database using a text editor like sublime, then adding the file within our directory (next to the php files) and use php to refer the database? Or must it only be created within a server itself and only accessible through the server? Is there another way to bypass databases? what i mean is implement other forms of storing users and their information or is database the simple and easier way of approaching that specific problem?

Any insist is appreciated it! PHP is understandable but ive never tinkered with MySQL so that is different in its own approach! Thank You!

One way and I am sure there are many others.

To practise it is best to create a temporary table to prevent corrupting your existing data,

  1. With PhpMyAdmin select any “existing” table.
  2. Select “Operations” which may in the dropdown menu “More” tab
  3. Copy “existing” to “temporary” table
    a, with option “Structure Only”
    b. tick all the checkbox options
    c. select “Go” to create empty “temporary” table
  4. Ensure “temporary” table is selected
  5. Select “Export” from the tabbed menu.
  6. accept defaults and select “Go”
  7. select “open in editor” to see the SQL statement

Notice the format and especially the “**CREATE TABLE” statements.

The SQL statement can be copied and pasted into the SQL tabbed menu options or used with PHP.

Output:

-- phpMyAdmin SQL Dump
-- version 4.5.4.1deb2ubuntu1
-- http://www.phpmyadmin.net
--
-- Host: localhost
-- Generation Time: Jun 20, 2016 at 12:22 PM
-- Server version: 5.7.12-0ubuntu1
-- PHP Version: 7.0.4-7ubuntu2.1

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;

--
-- Database: `ambasensedb`
--

-- --------------------------------------------------------

--
-- Table structure for table `temporary`
--

CREATE TABLE `temporary` (
  `id` int(10) NOT NULL,
  `field1` varchar(10) NOT NULL,
  `field2` varchar(10) NOT NULL,
  `field3` int(10) NOT NULL,
  `date`   datetime NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;

--
-- Indexes for dumped tables
--

--
-- Indexes for table `temporary`
--
ALTER TABLE `temporary`
  ADD PRIMARY KEY (`id`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `temporary`
--
ALTER TABLE `temporary`
  MODIFY `id` int(10) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=21577;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
2 Likes

Could you elaborate more on that? Im not near my laptop no more so i can test it but from what it sounds like, your saying i should download an existing table into my local computer that way I can open it with my IDE or text editor and see how it was created (syntax). However, lets say i do edit it and find myself wanting to add it back into the server. I’m assuming i would need to add it with phpmyadmin rather than dropping it into a directory. Also your last few statements made it seem like i can have both sql file and php work together side by side without needing a server (besides the server needed to run a php file)

When you have access to your laptop try creating a database using PHP:

<?php
$servername = "localhost";
$username   = "username";
$password   = "password";

// Create connection
$conn = new mysqli($servername, $username, $password);
  // Check connection
  if ($conn->connect_error)
  {
      die("Connection failed: " . $conn->connect_error);
  }
	
// Create database
   $sql = "CREATE DATABASE myDB";
   if ($conn->query($sql) === TRUE)
   {
      echo "Database created successfully";
   }else{
      echo "Error creating database: " . $conn->error;
   }
   $conn->close();

1 Like

Yeah i like that better, using php to manipulate a database or wait am i only able to create a database in php and noy manipulate it? Also would you recommend id do this with php or should i simply learn how to keep the entities both seperate?

Also im assuming id call this connect.php, then that means i would only need to call it once within a main php file otherwise id be creating more and more databases or does it not matter since the server knows how many to create?

Did you follow the W3Schools link

The tutorial details how you can create, delete, update, databases, tables, indexii, etc and shows numerous examples.

When you have access to your laptop please complete the full tutorial. If you have any further questions please feel free to supply the relevant script and state your problems.

You don’t create a database using PHP or anything. PHP is just a scripting language which has built in connection procedures so you can connect to the server which hosts that database and manipulate it.

So whether you use PHPMyAdmin or PHP directly, it doesn’t matter.

You could also use a command screen to create, manipulate or delete your database. Or any benchmarking tool (that really depends on your hosting. Shared hosting do not allow remote connections for security reasons but other types of hosting often do)

The important instruction here is the SQL order that creates that database.

“CREATE DATABASE Whatever_Name”

After that, you’ll need to create tables with its fields, primary keys, etc.

1 Like

After sitting down and reading, i realize the simplicity of SQL. I gained access to myphpadmin from my WAMPP and was both able to create and see the database. My goal now is being able to modify it utilizing myphpadmin as well as connecting to it using php. Also i need to learn how to call specific portions of the database and add/edit values already within the database. However, thats a matter of simply reading documentation and seeing more examples.

Thank you all for the help and clarification!

1 Like

This is helpful, helps me connect to my database. Thank You

1 Like

Actually, if you look at the code, he just did :wink:

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.