Difference between revisions of "Connecting to mysql"

From MyWiki
Jump to: navigation, search
(Created page with "<source lang="php"> //closing Example (MySQLi Procedural) mysqli_close($conn); </source>")
 
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
 +
http://www.w3schools.com/php/php_mysql_insert.asp<br>
 +
 
<source lang="php">
 
<source lang="php">
//closing
+
 
 +
////Example (MySQLi Procedural)
 +
<?php
 +
$servername = "localhost";
 +
$username = "username";
 +
$password = "password";
 +
 
 +
// Create connection
 +
$conn = mysqli_connect($servername, $username, $password);
 +
 
 +
// Check connection
 +
if (!$conn) {
 +
    die("Connection failed: " . mysqli_connect_error());
 +
}
 +
echo "Connected successfully";
 +
 +
 
 +
 
 +
//closing the connection
 
Example (MySQLi Procedural)
 
Example (MySQLi Procedural)
 
mysqli_close($conn);  
 
mysqli_close($conn);  
  
  
 +
// Example of inserting into a table
 +
 +
$sql = "INSERT INTO MyGuests (firstname, lastname, email)
 +
VALUES ('John', 'Doe', 'john@example.com')";
 +
 +
if ($conn->query($sql) === TRUE) {
 +
    echo "New record created successfully";
 +
} else {
 +
    echo "Error: " . $sql . "<br>" . $conn->error;
 +
}
 +
?>
 
</source>
 
</source>

Latest revision as of 17:57, 10 November 2014

http://www.w3schools.com/php/php_mysql_insert.asp

////Example (MySQLi Procedural)
<?php
$servername = "localhost";
$username = "username";
$password = "password";
 
// Create connection
$conn = mysqli_connect($servername, $username, $password);
 
// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
} 
echo "Connected successfully";
 
 
 
//closing the connection 
Example (MySQLi Procedural)
mysqli_close($conn); 
 
 
// Example of inserting into a table
 
$sql = "INSERT INTO MyGuests (firstname, lastname, email)
VALUES ('John', 'Doe', 'john@example.com')";
 
if ($conn->query($sql) === TRUE) {
    echo "New record created successfully";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}
?>