/*CREATE database test123 CHARACTER SET utf8 COLLATE utf8_general_ci;
USE test123;
CREATE TABLE test(
id INT UNSIGNED AUTO_INCREMENT,
name VARCHAR (50),
mark INT UNSIGNED,
PRIMARY KEY(id)
);
INSERT INTO test (name, mark) VALUES ('Иннокентий', 120), ('Афанасий', 190), ('Геннадий', 140);*/
<?php
header ( 'Content-type: text/html;charset=utf8' ) ; $pdo = new PDO( 'mysql:host=localhost;dbname=test123' , 'root' , '' ) ;
$pdo -> setAttribute ( PDO:: ATTR_ERRMODE , PDO:: ERRMODE_EXCEPTION ) ;
$pdo -> query ( "SET NAMES utf8" ) ;
$sql = "SELECT id, name, mark FROM test ORDER BY :order LIMIT 0, 100" ;
$stmt = $pdo -> prepare ( $sql ) ;
$order = 'name' ;
$stmt -> bindValue ( ':order' , $order , PDO:: PARAM_STR ) ;
$stmt -> execute ( ) ;
$result = $stmt -> fetchAll ( ) ;
echo '<table>' ;
foreach ( $result as $row ) {
echo '<tr>' ;
echo "<td>{$row['id']} </td>" ;
echo "<td>{$row['name']} </td>" ;
echo "<td>{$row['mark']} </td>" ;
echo '</tr>' ;
}
echo '</table>' ;
LypDUkVBVEUgZGF0YWJhc2UgdGVzdDEyMyBDSEFSQUNURVIgU0VUIHV0ZjggQ09MTEFURSB1dGY4X2dlbmVyYWxfY2k7ClVTRSB0ZXN0MTIzOwpDUkVBVEUgVEFCTEUgdGVzdCgKICAgIGlkIElOVCBVTlNJR05FRCBBVVRPX0lOQ1JFTUVOVCwKICAgIG5hbWUgVkFSQ0hBUiAoNTApLAogICAgbWFyayBJTlQgVU5TSUdORUQsCiAgICBQUklNQVJZIEtFWShpZCkKKTsKSU5TRVJUIElOVE8gdGVzdCAobmFtZSwgbWFyaykgVkFMVUVTICgn0JjQvdC90L7QutC10L3RgtC40LknLCAxMjApLCAoJ9CQ0YTQsNC90LDRgdC40LknLCAxOTApLCAoJ9CT0LXQvdC90LDQtNC40LknLCAxNDApOyovCgo8P3BocApoZWFkZXIoJ0NvbnRlbnQtdHlwZTogdGV4dC9odG1sO2NoYXJzZXQ9dXRmOCcpOwokcGRvID0gbmV3IFBETygnbXlzcWw6aG9zdD1sb2NhbGhvc3Q7ZGJuYW1lPXRlc3QxMjMnLCdyb290JywnJyk7CiRwZG8tPnNldEF0dHJpYnV0ZShQRE86OkFUVFJfRVJSTU9ERSwgUERPOjpFUlJNT0RFX0VYQ0VQVElPTik7CiRwZG8tPnF1ZXJ5KCJTRVQgTkFNRVMgdXRmOCIpOwokc3FsID0gIlNFTEVDVCBpZCwgbmFtZSwgbWFyayBGUk9NIHRlc3QgT1JERVIgQlkgOm9yZGVyIExJTUlUIDAsIDEwMCI7CiRzdG10ID0gJHBkby0+cHJlcGFyZSgkc3FsKTsKJG9yZGVyID0gJ25hbWUnOwokc3RtdC0+YmluZFZhbHVlKCc6b3JkZXInLCAkb3JkZXIsIFBETzo6UEFSQU1fU1RSKTsKJHN0bXQtPmV4ZWN1dGUoKTsKJHJlc3VsdCA9ICRzdG10LT5mZXRjaEFsbCgpOwoKZWNobyAnPHRhYmxlPic7CmZvcmVhY2goJHJlc3VsdCBhcyAkcm93KXsKICAgIGVjaG8gJzx0cj4nOwogICAgZWNobyAiPHRkPnskcm93WydpZCddfTwvdGQ+IjsKICAgIGVjaG8gIjx0ZD57JHJvd1snbmFtZSddfTwvdGQ+IjsKICAgIGVjaG8gIjx0ZD57JHJvd1snbWFyayddfTwvdGQ+IjsKICAgIGVjaG8gJzwvdHI+JzsKfQplY2hvICc8L3RhYmxlPic7
stdout
/*CREATE database test123 CHARACTER SET utf8 COLLATE utf8_general_ci;
USE test123;
CREATE TABLE test(
id INT UNSIGNED AUTO_INCREMENT,
name VARCHAR (50),
mark INT UNSIGNED,
PRIMARY KEY(id)
);
INSERT INTO test (name, mark) VALUES ('Иннокентий', 120), ('Афанасий', 190), ('Геннадий', 140);*/
stderr
PHP Warning: Cannot modify header information - headers already sent by (output started at /home/oyMgx3/prog.php:11) in /home/oyMgx3/prog.php on line 12
PHP Fatal error: Uncaught exception 'PDOException' with message 'could not find driver' in /home/oyMgx3/prog.php:13
Stack trace:
#0 /home/oyMgx3/prog.php(13): PDO->__construct('mysql:host=loca...', 'root', '')
#1 {main}
thrown in /home/oyMgx3/prog.php on line 13