Bonjour,
Je prépare un script pour faire des "slug" de nom/prénoms, mais dès le début cela ne marche pas, j'ai une erreur "General error: mode must be an integer" , alors que j'ai bien un entier (j'ai même un entier par défault '1000' , auriez-vous une idée s'il vous plait ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7 ( ! ) Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: mode must be an integer in C:\UwAmp\www\slug.php on line 57 ( ! ) PDOException: SQLSTATE[HY000]: General error: mode must be an integer in C:\UwAmp\www\slug.php on line 57 Call Stack # Time Memory Function Location 1 0.0023 365656 {main}( ) ...\slug.php:0 2 0.0132 425160 checkIfPlayerSlugExists( ) ...\slug.php:68 3 0.0176 438544 query ( ) ...\slug.php:57
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44 function cnx_pdo(){ global $debug,$var_site,$log_error; $db = "sportmonks"; $host="localhost"; $user="root"; $pass="root"; $charset = 'utf8mb4'; //$dsn = "mysql:host=$host;dbname=$db;charset=$charset"; $dsn = "mysql:host=$host;charset=$charset"; $options = [ PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, PDO::ATTR_EMULATE_PREPARES => false, ]; try { $pdo = new PDO($dsn, $user, $pass, $options); } catch (\PDOException $e) { echo $e->getMessage(); error_log("Erreur cnx bdd"); throw new \PDOException($e->getMessage(), (int)$e->getCode()); } return($pdo); } function checkIfPlayerSlugExists($slug, $id) { $pdo_c = cnx_pdo(); $id=1000; return $pdo_c->query('SELECT id FROM sportmonks.players_tmp2 WHERE slug = :slug AND id != :id LIMIT 1', ['slug' => $slug, 'id' => $id])->fetchAll(); } $pdo = cnx_pdo(); $query = $pdo->prepare("SELECT * FROM sportmonks.players_tmp2 ORDER BY display_name ASC"); $query->execute(); $players = $query->fetchAll(); foreach($players as $player){ $slug=$player["display_name"]; $doSlugExist = checkIfPlayerSlugExists($slug, $player['id']); if (count($doSlugExist) > 0 ) echo "fff"; }
Code SQL : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12 CREATE TABLE `players_tmp2` ( `id` bigint(20) NOT NULL, `display_name` varchar(255) DEFAULT NULL, `slug` varchar(255) DEFAULT NULL ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4; -- -- Contenu de la table `players_tmp2` -- INSERT INTO `players_tmp2` (`id`, `display_name`, `slug`) VALUES (47, 'Fábio Aurélio', NULL);
Partager