you should use mysql class and PDO also instead
1. Mysql class
$conn= new mysqli('your-server-name','database-name','database-password','database-name');// not needed mysql_select_db function
$query= "select * form tablename";
if ($result = $mysqli->query($query)) {
while ($row = $result->fetch_row()) {
printf("%s (%s,%s)\n", $row[0], $row[1], $row[2]);
}
/* free result set */
$result->close();
}
you can prepare statement before run it .
like
$query = "INSERT INTO tablename(`field-1`,`field-2`) VALUES (?,?)";
$stmt = $mysqli->prepare($query);
// now you can replace blank value in query with as many time as you want with bind
$stmt = $stmt ->bind_param("ss","value-1",'value-2');
//first argument stand for value type here s for string value
/* execute prepared statement */
$stmt->execute();
yes Mysql extension deprecated soon in php 7 , should be replaced with Mysqli
so mysql_connect should be replace with mysqli_connect
$conn=mysqli_connect('your-server-name','database-name','database-password');
//instead of $conn=mysql_connect('yourserver','database-name','database-password');
mysqli_select_db($conn,"database-name");// need to pass the connection reference as first argument
//instead of mysql_select_db("database-name");
mysqli_query($conn,"select * from tablename");
//instead of msyql_query("select * from tablename");
so in short use mysqli instead of mysql and pass the connection as first argument in the function .
but this function also removed in future version so avoid to use it also