Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
projet-cdaw
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Thibaut Felten
projet-cdaw
Commits
97c6d7f6
Commit
97c6d7f6
authored
Nov 09, 2020
by
thibaut-felten
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
TP PDO
parent
7d6d2e97
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
64 additions
and
0 deletions
+64
-0
initPDO.php
backend/tp1/initPDO.php
+22
-0
testPDO.php
backend/tp1/testPDO.php
+42
-0
No files found.
backend/tp1/initPDO.php
0 → 100644
View file @
97c6d7f6
<?php
define
(
'_MYSQL_HOST'
,
'127.0.0.1'
);
define
(
'_MYSQL_PORT'
,
3306
);
define
(
'_MYSQL_DBNAME'
,
'dbtest'
);
define
(
'_MYSQL_USER'
,
'root'
);
define
(
'_MYSQL_PASSWORD'
,
'root'
);
$connectionString
=
"mysql:host="
.
_MYSQL_HOST
;
if
(
defined
(
'_MYSQL_PORT'
))
$connectionString
.=
";port="
.
_MYSQL_PORT
;
$connectionString
.=
";dbname="
.
_MYSQL_DBNAME
;
$options
=
array
(
PDO
::
MYSQL_ATTR_INIT_COMMAND
=>
'SET NAMES utf8'
);
try
{
$pdo
=
new
PDO
(
$connectionString
,
_MYSQL_USER
,
_MYSQL_PASSWORD
,
$options
);
$pdo
->
setAttribute
(
PDO
::
ATTR_ERRMODE
,
PDO
::
ERRMODE_EXCEPTION
);
}
catch
(
PDOException
$erreur
)
{
myLog
(
'Erreur : '
.
$erreur
->
getMessage
());
}
\ No newline at end of file
backend/tp1/testPDO.php
0 → 100644
View file @
97c6d7f6
<!DOCTYPE html>
<html
lang=
"fr"
>
<head>
<meta
charset=
"UTF-8"
>
<meta
name=
"viewport"
content=
"width=device-width, initial-scale=1.0"
>
<title>
TP1
</title>
</head>
<body>
<h1>
Users
</h1>
<table>
<thead>
<tr>
<th>
Id
</th>
<th>
Name
</th>
<th>
Email
</th>
</tr>
</thead>
<tbody>
<?php
// initialise une variable $pdo connecté à la base locale
require_once
(
"initPDO.php"
);
// cf. doc / cours
$request
=
$pdo
->
prepare
(
"select * from users"
);
// à vous de compléter...
// afficher un tableau HTML avec les donnéees en utilisant fetch(PDO::FETCH_OBJ)
/*** close the database connection ***/
$request
->
execute
();
while
(
$result
=
$request
->
fetch
()){
echo
(
"<tr>"
);
echo
(
"<td>"
.
$result
[
"id"
]
.
"</td>"
);
echo
(
"<td>"
.
$result
[
"name"
]
.
"</td>"
);
echo
(
"<td>"
.
$result
[
"email"
]
.
"</td>"
);
echo
(
"</tr>"
);
}
echo
(
"</table"
);
?>
</tbody>
</table>
</body>
</html>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment