+ 2
How can I store the result of a mysql query to a PHP variable?
I want to store a result of mysql query to a PHP variable. Can anyone tell me how to do it?
6 Réponses
+ 5
mysql is no longer supported by php you will have to use mysqli framework or PDO(php data object) framework.
I am going to demonstrate using mysqli framework
so the correct ans is like this...
$result = mysqli_query("your query");
0
Well its easy. Use the following syntax :
$result= mysql_query("..your query..");
Note that this variable can also store multiple rows depending on your query.
Also note that statements other than "select" will return the no of rows affected.
0
use PDO ithink is more goos than mysqli
0
<?PHP
$conn= mysqli_connect("localhost","root","");
mysqli_select_db("database name");
$username= $_POST['username'];
$password= $_POST['password'];
$sql= "INSERT INTO 'tablename' (username, password) VALUES ('$username','$password') ";
$e= mysql_query($sql);
?>
0
??
- 1
$res= mysql_query(" query");