Skip to main content

Creating Database(SQL)


Create a database if it does not exist!

SQL























-Stands for  Structured Query Language

Used to manage database //Update data on a database or retrieve data from a database


Start by creating your connection
$servername="localhost"
$username="root"
$password=""
Connect to MySQL
$link = mysql_connect($servername, $username, $password);
if (!link)
{
die('Could not connect ' . mysql_error());
}
Suppose we're creating a database with name 'test'. You must first of all make that db your current db.
$db_selected = mysql_select_db('test', $link);
You can now create your database with an appropriate name!
if (!db_selected)
{
$sql = 'CREATE DATABASE test';
if (mysql_query($sql, $link))
{
echo "Database test has been successfully made!";
require table.php;
}
else
{
echo "Error creating database: " . mysql_error() . "\n";
}
}
mysql_close($link);
?> 

Note: You might be wondering why am I calling a table.php when the db is successfully created.
Well, this is not mandatory. I called the table.php because it will create a database table with given name.

Creating the database table

Suppose we are creating a database table with name test-table in our database.

This time while connecting to MySQL, you should insert your $dbname!
$conn = new mysqli($servername, $username, $password, $dbname); 

After connecting to MySQL, you can start creating your database table.
$sql = "CREATE TABLE test.test-table"
(
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
firstname VARCHAR(30) NOT NULL,
lastname VARCHAR(30) NOT NULL,
email VARCHAR(50),
)";
We've created our table name with:
1. id //declared as Integer and it will auto increment as well with length 6
2. firstname //declared as Varchar and length 30
3. lastname //decared asVarchar with length 30
4. email // declared as Varchar with length 50

Check if table has been created successfully!
if ($conn->query($sql) === TRUE)
{
echo "Table test_table created successfully";
}
else
{
echo "Error creating table: " . $conn->error;
}
?>
Get in on github



Popular posts from this blog

Learn how to make an auto login bot with Autoit

Start by creating a new directory and make an autoit script. Edit the script and include IE.au3: #include    Suppose we're writing a script which will allow a anyone to sign in his facebook on a scheduled time automatically. It's simple, don't panic! You need to call a function with any name you want. Let's take loginfb() ! call ("loginfb") So, we only have to write the function loginfb now! Func loginfb() Global $oIE = _IECreate ("https://www.facebook.com/") Local $username = _IEGetObjByName ($oIE, "email") Local $password = _IEgetObjByName ($oIE, "pass") Local $button = _IEGetObjById ($oIE, "loginbutton") _IEFormElementSetValue ($username, "") // your email here! _IEFormElementSetValue ($password, "") //your fb password here! Send("{Enter}") EndFunc $username and $password are variables. "email" and "pass" are the names given to the textarea

How to disable SSLv3 in ubuntu?

Why disable SSL 3.0? SSLv3 is not sufficiently secure. The replacement versions, in particular, Transport Layer Security(TLS) 1.2, are way more secure and capable protocols.  Poodle attack and End of SSLv3  In late September, a team at Google discovered a serious vulnerability(POODLE) in SSLv3 that can be exploited to steal confidential information, e.g things like cookies and passwords, enabling the latter to access a user's private account on a social website. You can learn more about SSL on our Android app SSLearn. Steps: Firstly, let's start with an Update: After the update, install apache: Note: If you already have apache installed, you may skip this step. After installing apache, type the following command to configure and disable SSLv3: Then simply press the arrow down on your keyboard and search for SSLprotocol. Add '-SSLv2 -SSLv3' at the end. Then 3 lines upwards, you should be able to see #SSLHonorCipher

How to install the FReMP Stack on Ubuntu 20.04?

Technology keeps on evolving everyday and developers constantly look for more and more things to get their hands-on. In this article, I will be introducing a new full stack framework, called FReMP . The abbreviation used is not the best one, but it just gets the work done in justifiable ways. What on earth is FReMP stack? The FReMP stack is a highly scalable full stack framework, which can be used to build awesome web apps. The acronym stands for F lask, Re actJS, M ongodb and P ython. Unlike other famous stacks such as MEAN and MERN, the FReMP stack uses Python to handle back-end operations. Examples of such operations can be machine learning and artificial intelligence operations, web scraping tools or digital image processing. Step 0: Update your list of installed packages While this is optional, it is always a good practice to update your list of packages and upgrade them for newer versions before starting any installation on your environment. Run the following to do so: $ apt-get