+ 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?

23rd Dec 2016, 12:15 PM
Twaha Rahman
Twaha Rahman - avatar
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");
26th Dec 2016, 1:22 PM
Raniket Ram
Raniket Ram - avatar
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.
25th Dec 2016, 4:41 AM
Tanmay Kshirsagar
Tanmay Kshirsagar - avatar
0
use PDO ithink is more goos than mysqli
27th Dec 2016, 12:24 AM
Nabil Ameziane
Nabil Ameziane - avatar
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); ?>
28th Dec 2016, 8:09 AM
deepak dadwal
deepak dadwal - avatar
0
??
28th Dec 2016, 1:17 PM
Nader elsaid
Nader elsaid - avatar
- 1
$res= mysql_query(" query");
27th Dec 2016, 7:54 PM
abimbola david
abimbola david - avatar