Mysql database connectivity with PHP:
<?php/* Database config */
$db_host = 'localhost'; server name
$db_user = 'tnjnorbert'; mysql username
$db_pass = 'password'; mysql password
$db_database = 'records'; // database name
/* End config */
$db = new PDO('mysql:host='.$db_host.';dbname='.$db_database, $db_user, $db_pass);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
?>
how to insert data into MySQL database using the config.php above
<form action="" method="post">
<input type="text" name="username">
<input type="text" name="password">
<?php
include 'config.php';
$username=$_POST['username'];
$password=$_POST['password'];
$query=mysql_query("insert into table_name(username,password) values("$username","$password");
if($query){
echo 'data successfully added to the database';
}
?>
</form>
how to connect to mysql using strict php mysql functions
<?php
$host="localhost";
$username="mysqlusername";
$password="mysqlpassword";
$db_name="databasename";
$connect=mysql_connect($host,$username,$password);
$select_db=mysql_select_db($connect,$db_name);
if($select_db){
echo "database selected";
}else{
echo "error ".mysql_error();
}
?>
This comment has been removed by the author.
ReplyDelete