कृपया mysql_connect का उपयोग न करने का प्रयास करें इसके बजाय mysqli_connect . का उपयोग करें या PDO_MySQL इसे पढ़ें
die<का भी उपयोग करें /ए> यह पता लगाने के लिए कि आपके कोड में कोई त्रुटि है या नहीं
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
अन्यथा (अनुशंसित तरीका)-
प्रक्रियात्मक शैली
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "INSERT INTO Persons (firstname, lastname, email)
VALUES ('Happy', 'John', '[email protected]le.com')";
if (mysqli_query($conn, $sql)) {
echo "New Person created successfully";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
mysqli_close($conn);
MySQLi ऑब्जेक्ट-ओरिएंटेड स्टाइल
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO Persons (firstname, lastname, email)
VALUES ('Happy', 'John', '[email protected]')";
if ($conn->query($sql) === TRUE) {
echo "New Person created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();