How can SQL be used to create a two-column table for PHP usage?
To create a two-column table for PHP usage using SQL, you can use the following SQL query: ```sql CREATE TABLE my_table ( column1 VARCHAR(50), column2 INT ); ``` This query creates a table named `my_table` with two columns: `column1` of type `VARCHAR` and `column2` of type `INT`. This table can then be accessed and manipulated using PHP.
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// SQL query to create a two-column table
$sql = "CREATE TABLE my_table (
column1 VARCHAR(50),
column2 INT
)";
if ($conn->query($sql) === TRUE) {
echo "Table created successfully";
} else {
echo "Error creating table: " . $conn->error;
}
$conn->close();
?>
Keywords
Related Questions
- What are the differences between Java and JavaScript in terms of usage in PHP?
- What is the significance of using the strict comparison operator (===) in PHP when comparing arrays?
- How can JavaScript be integrated with PHP to manage form submission errors and prevent the "Page no longer current" message in browsers?