Hello friends;
Firstly; connect to our database with the following code :
Php ile tek veri çekme kodu :
<?php
$db_host = "localhost";
$db_name = "my_database_name";
$db_username = "my_database_username";
$db_password = "my_database_username_password";
$connect = new PDO("mysql:host=$db_host;dbname=$db_name", $db_username, $db_password);
$connect->exec("SET NAMES 'utf8'; SET CHARSET 'utf8'");
?>
$db_host = "localhost";
$db_name = "my_database_name";
$db_username = "my_database_username";
$db_password = "my_database_username_password";
$connect = new PDO("mysql:host=$db_host;dbname=$db_name", $db_username, $db_password);
$connect->exec("SET NAMES 'utf8'; SET CHARSET 'utf8'");
?>
Now let's select single row one query in database with pdo :
<?php
$id = $_GET["id"];
$statement = $connect->prepare("SELECT * FROM my_table WHERE id = :id");
$statement->execute(array( ":id" => $id ));
$duzenle = $statement->fetch(PDO::FETCH_ASSOC);
if( $statement->rowCount() ){
echo $duzenle["id"];
}
?>
$id = $_GET["id"];
$statement = $connect->prepare("SELECT * FROM my_table WHERE id = :id");
$statement->execute(array( ":id" => $id ));
$duzenle = $statement->fetch(PDO::FETCH_ASSOC);
if( $statement->rowCount() ){
echo $duzenle["id"];
}
?>
Its very simple. Here, table name is my_table.
I hope it has been useful.
İlk Yorumu Sen Yap