armelk1999
Messages postés24Date d'inscriptionmardi 17 juillet 2018StatutMembreDernière intervention14 avril 2019
-
Modifié le 17 juil. 2018 à 17:58
jordane45
Messages postés37290Date d'inscriptionmercredi 22 octobre 2003StatutModérateurDernière intervention30 mars 2023
-
31 juil. 2018 à 17:00
BONJOUR regarder un peu ce code s'il vous plait.lorsque je le compile on me signale des erreurs:
<?php
function db_query($db_name, $sql) {
$sql = str_replace("# ", "", $sql); // basic shield against sql injections
$sql = str_replace("#' ", "", $sql);
global $db_connection_type, $db_server_address, $db_user, $db_password;
switch($db_connection_type) {
case "odbc":
$db_connection = odbc_connect($db_name, $db_user, $db_password);
$result = odbc_exec($db_connection, $sql);
break;
case "mysql":
$db_connection = mysql_connect($db_server_address, $db_user, $db_password);
$result = mysql_query($db_name, $sql, $db_connection);
}
return $result;
}
function fetch_array($array) {
global $db_connection_type;
switch($db_connection_type) {
case "odbc":
$result = odbc_fetch_array($array);
break;
case "mysql":
$result = mysql_fetch_array($array);
}
return $result;
}
?>
EDIT : AJout des balises de code (et du "bonjour" ) !
OpenBookings.org is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
OpenBookings.org is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OpenBookings.org; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
mysql_query() expects at most 2 parameters, 3 given
Et quand tu regardes ton code :
mysql_query($db_name, $sql, $db_connection);
tu vois bien qu'il y a trois paramètres...... alors qu'il ne devrait y en avoir que deux!
En regardant La documentation Tu peux voir que pour l'utiliser il suffit de :
3 - Mais vu que tu as un script connect_db.php ... pourquoi vouloir le modifier ???
Ce script utilise mysqli qui est préférable à l'ancienne extension mysql que toi tu essayes d'utiliser....
As tu au moins lu les liens que je t'avais donné ?????!!!!
armelk1999
Messages postés24Date d'inscriptionmardi 17 juillet 2018StatutMembreDernière intervention14 avril 2019 23 juil. 2018 à 17:24
merci . désolé je me suis juste un peu précipité
armelk1999
Messages postés24Date d'inscriptionmardi 17 juillet 2018StatutMembreDernière intervention14 avril 2019 23 juil. 2018 à 17:31
en fait j'utilise wampserver 2.5 et je ne sais si c'est a cause que ce code ne marche pas.devrais-je telecharger une version de php et wampserver superiur a celle que j'aie?
23 juil. 2018 à 10:59
Warning: mysql_fetch_array() expects parameter 1 to be resource, null given in C:\wamp\www\openbookings\connect_db.php on line 64
essaie un peu d'y jetter un oeil.
23 juil. 2018 à 11:16
<?php
/* OpenBookings - Copyright (C) 2005-2007 Jérôme ROGER (jerome@openbookings.org)
connect_db.php - This file is part of OpenBookings.org (http://www.openbookings.org)
OpenBookings.org is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
OpenBookings.org is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with OpenBookings.org; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
// Database connection mode abstraction (2 functions)
// Connects to database according the selected connection type
function db_query($db_name, $sql) {
$sql = str_replace("# ", "", $sql); // basic shield against sql injections
$sql = str_replace("#' ", "", $sql);
global $db_connection_type, $db_server_address, $db_user, $db_password;
switch($db_connection_type) {
case "odbc":
$db_connection = odbc_connect($db_name, $db_user, $db_password);
$result = odbc_exec($db_connection, $sql);
break;
case "mysql":
$db_connection = new mysqli($db_server_address, $db_user, $db_password);
// $servername = "localhost";
// $username = "root";
// $password = "";
// $dbname = "openbookings";
// $db_connection=new mysqli($servername,$username,$password,$dbname);
// if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error);}
$result =mysql_query($db_name, $sql, $db_connection);
}
return $result;
}
function fetch_array($array) {
global $db_connection_type;
switch($db_connection_type) {
case "odbc":
$result = odbc_fetch_array($array);
break;
case "mysql":
$result = mysql_fetch_array($array);
}
return $result;
}
?>
23 juil. 2018 à 12:15
Explications disponibles ici :
https://codes-sources.commentcamarche.net/faq/11288-les-balises-de-code
2 - Le message d'erreur est pourtant clair
Et quand tu regardes ton code :
tu vois bien qu'il y a trois paramètres...... alors qu'il ne devrait y en avoir que deux!
En regardant La documentation Tu peux voir que pour l'utiliser il suffit de :
ou éventuellement
AU passage, il te manque l'instruction pour selectionner la BDD .....
Voir la documentation officielle de php : http://php.net/manual/fr/function.mysql-query.php
3 - Mais vu que tu as un script connect_db.php ... pourquoi vouloir le modifier ???
Ce script utilise mysqli qui est préférable à l'ancienne extension mysql que toi tu essayes d'utiliser....
As tu au moins lu les liens que je t'avais donné ?????!!!!
23 juil. 2018 à 17:24
23 juil. 2018 à 17:31