Mysql
mysql_connect($db _host,$db _user,$db _password); mysql_select_db($dn _name); $result=mysql_query("Select ' Name ' from ' The Users ' WHERE ' location ' = '$location‘"); while($row=Mysql_fetch_array($result,Mysql_assoc)) { Echo $row[' Name ']; } Mysql_free_result($result);
Mysqli
$mysqli=NewMysqli ($db _host,$db _user,$db _password,$db _name); $sql= "INSERT into ' users ' (ID, name, gender, location) VALUES (?,?,?,?)"; $stmt=$mysqli->prepare ($sql); $stmt->bind_param (' Dsss ',$source _id,$source _name,$source _gender,$source _location);//four parameters so it's dsss. \ string$stmt-execute ();$stmt->bind_result ($id,$name,$gender,$location); while($stmt-Fetch ()) { Echo $id.$name.$gender.$location; } $stmt-close ();$mysqli->close ();
Pdo
$dsn= "mysql:host=$db _host;d bname=$db _name"; $DBH=NewPDO ($dsn,$db _user,$db _password); $sql= "SELECT ' Name ', ' Location ' from ' Users ' WHERE ' location ' =?, ' name ' =? '; $sth=$DBH->prepare ($sql); $sth->execute (Array($location,$name)); $result=$sth->fetch (PDO::fetch_obj); Echo $result->name.$result-Location ;$DBH=NULL;
Mysqli and MySQL and PDO queries