public function connect() { if (!function_exists('mysqli_connect')) { throw new DbError('class mysqli_connect doesn\'t exist: no MySQL interface'); } $this->conn = mysqli_connect($this->host, $this->user, $this->passwd, $this->name); if (mysqli_connect_error()) { throw new DbError('mysql connect error(' . mysqli_connect_errorno() . ') - ' . mysqli_connect_error()); } }
<?php /* * Used to provide a connection to the database */ define('DB_USER', 'redavni_admin'); define('DB_PASS', '4dvx_TSb5.wP'); define('DB_HOST', 'bitknight.com'); define('DB', 'redavni_notes'); define('DB_PORT', 3306); // no reason to supply unless changed from 3306 // Connect $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB); // Verify if (!$dbc) { die('Connect error: (' . mysqli_connect_errorno() . ') ' . mysqli_connect_error()); }
<html> <head> <title>Insert Multiple Data</title> </head> <body> <?php $servername = "localhost"; $username = "******"; $password = ""; $dbname = "mydb"; //create connection $conn = mysqli_connect($servername, $username, $password, $dbname); //check connection if (!$conn) { die("Connection Failed :" . mysqli_connect_errno() . " " . mysqli_connect_error()); } $sql = "INSERT INTO myguest(firstname,lastname,email)\n\t\t\tVALUES('John','Doe','*****@*****.**');"; $sql .= "INSERT INTO myguest(firstname, lastname, email)\n\t\t\tVALUES ('Mary', 'Moe', '*****@*****.**');"; $sql .= "INSERT INTO myguest(firstname, lastname, email)\n\t\t\tVALUES ('Julie', 'Dooley', '*****@*****.**')"; if (mysqli_multi_query($conn, $sql)) { echo "New records created successfully"; } else { echo "Error:" . $sql . "<br>" . mysqli_connect_errorno($conn) . " " . mysqli_error($conn); } mysqli_close($conn); ?> </body> </html>