connect_error) { die("Connection failed: " . $conn->connect_error); } echo "Connected successfully"; ?>"> connect_error) { die("Connection failed: " . $conn->connect_error); } echo "Connected successfully"; ?>">
Download presentation
Presentation is loading. Please wait.
Published byPirkko Leppänen Modified over 5 years ago
2
Conection <?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); } echo "Connected successfully"; ?>
3
Select data $sql = "SELECT id, firstname, lastname FROM MyGuests"; $result = $conn->query($sql); if ($result->num_rows > 0) { // output data of each row while($row = $result->fetch_assoc()) { echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br>"; } } else { echo "0 results"; }
4
create table in database
//create table in database $sql1 = " CREATE TABLE IF NOT EXISTS `test` ( `id` int(11) NOT NULL auto_increment, `type` text NOT NULL, `command` text NOT NULL, `value` text NOT NULL, UNIQUE KEY `id` (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1"; $maketable = mysql_query($sql1); if (!$maketable) { die('Could not create table: ' .mysql_error()); }
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.