Click here to Skip to main content
16,018,818 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all, hope all is well?

Please am new to this PDO thingy, how can I fetch data from my database just like this Mysql query below

PHP
<?php

include ("connect.php");


$email=@$_POST["email"];

$sql="SELECT sname,fname FROM user_db WHERE email='$email' ";
	$result=mysql_query($sql);

// Mysql_num_row is counting table row

$count=mysql_num_rows($result);

if($count==1){
	
$info=mysql_fetch_array($result);


$sname=$info['sname'];

$fname=$info['fname'];


}
else{
	
	echo "user details not found";
	
	}

?>


And how can I put the connection string of the PDO in another file and import and use it when need? Thanks
Posted
Comments
enhzflep 10-Jul-13 17:43pm    
What have you tried, where are you stuck? There are 474,000 results for the google search "pdo php tutorial"
tarhex 10-Jul-13 17:53pm    
which is the best to use:

fetch_assoc or fetch_both or fetch_num
enhzflep 10-Jul-13 18:14pm    
You replied to yourself. You need to hit the ( <- Reply ) button to the right of a comment, or the ( Have a Question or Comment? ) button to respond to a solution or a question.

That aside, No context given, no reasonable answer possible. I don't use any of the three, generally. When I do, it's whatever is the default.
enhzflep 10-Jul-13 19:02pm    
You replied to yourself. You need to hit the ( <- Reply ) button to the right of a comment, or the ( Have a Question or Comment? ) button to respond to a solution or a question.
tarhex 10-Jul-13 19:46pm    
ok, thanks for the hint.

<!--?php
$host = "localhost"; $db = "sample"; $user = "admin"; $pass = "tarhe";

$conn = new PDO("mysql:host=$host;dbname=$db",$user,$pass);

$sql = "SELECT * FROM search_info";

$q = $conn-?-->query($sql) or die("failed!");

$r = $q->fetch(PDO::FETCH_BOTH);

echo $r['userid']; ?>


In the place of fetch, I found out that fetch_assoc or fetch_both and some others can be used, they all produce the same result and I can't seem to find the difference.</xml?-->

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900