how to connect mysql database in php sample code

 


<?php
//Step1
$db = mysqli_connect("localhost","cpaneluser_dbusername","password","cpaneluser_dbname")
or die('Error connecting to MySQL server.');
?>

<html>
<head>
</head>
<body>
<h1>PHP connect to MySQL</h1>

<?php
//Step2

$query = "SELECT * FROM sampletable";
mysqli_query($db, $query) or die('Error querying database.');


//Step3
$result = mysqli_query($db, $query);

 

print_r($result);

//Step 4
mysqli_close($db);
?>

</body>
</html>

Click Here to learn more About MySQL database Connection settings

How do I create a MySQL database user

Was this answer helpful?

Related Articles

PHP-based Form Mail (Feedback) Script

Updatedhttps://www.domainindia.org/login/knowledgebase/116/PHP-sendmail-Settings.html

Perl-based Form Mail (Feedback) Script

 Perl-based Form Mail (Feedback) ScriptUsing a Perl script you may accept feedback from your...

Feedback Form Code / Instructions

Feedback Form Code / InstructionsThe source code for the two files (feedback.php and feedout.php)...

PHP sendmail Settings

Using phpMailer to Send Mail through PHP Download the PHPMailer script First, download...

301 Redirect from non-www to ww -- Without Looping!

o - you want to improve your search engine rankings, and SEO gurus told you that Google might be...