Anciennes révisionsLiens de retourExporter en PDFHaut de page Share via Share via... Twitter LinkedIn Facebook Pinterest Telegram WhatsApp Yammer RedditDerniers changementsSend via e-MailImprimerPermalien × PDO php, php7, mysql, PDO PHP Data Objects (PDO) est une extension définissant l'interface pour accéder à une base de données avec PHP. https://fr.wikipedia.org/wiki/PHP_Data_Objects Tips / Astuces connect function erp_connect_db_PDO() { //the VARIABLES in uppercase are stored in a config gile try { $login=DOLIBARR_LOGINMYSQL; // user name for you database $pass=DOLIBARR_PASSWORDMYSQL; // pass word to the database if you dont have a password $host=SERVERMYSQL; $dbname=DOLIBARR_DBMYSQL; $strConnection = 'mysql:host='.$host.';dbname='.$dbname; //Ligne 1 $arrExtraParam= array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"); //Ligne 2 $pdo = new PDO($strConnection, $login, $pass, $arrExtraParam); //Ligne 3; Instancie la connexion $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);//Ligne 4 } catch(PDOException $e) { $msg = 'ERREUR PDO dans ' . $e->getFile() . ' L.' . $e->getLine() . ' : ' . $e->getMessage(); die($msg); } return $pdo; } équivalent mysql_num_rows $req=$pdo->prepare($member0); $req->execute(); $reqN=$req->rowCount(); if($reqN!=1){ echo "bla!"; } loop results foreach ($req as $result) { echo $result["MySQL_variable_name"]; echo "<br/>"; } just one row function produit_libelle2($id,$pdo) { $sql="SELECT ref, label FROM llx_product WHERE rowid=".$id; $stmt = $pdo->query($sql); $row =$stmt->fetchObject(); $produit=$row->label; return($produit); } last insert id $lastId = $stmt->lastInsertId(); next row comment comparer les données de la ligne courante avec la précédente ou la suivante? pas possible de faire comme j'aimais avec mysql_result($row+1) ou mysql_result($row-1) solution: ajouter une variable locale dans la boucle, du genre: $current_discipline=""; //initialisation for(...) if($row['discipline'] != $current_discipline) { //est-ce que le champ discipline de la ligne courante est le même que la discipline courante? non -> ON CHANGE echo "<h1>" .$row['discipline'] ."</h1>"; $current_discipline=$row['discipline']; } else { //oui, on ne fait rien } Doc 'n books https://fr.wikipedia.org/wiki/PHP_Data_Objects https://www.univ-orleans.fr/iut-orleans/informatique/intra/tuto/php/ (epub) http://php.net/manual/fr/book.pdo.php http://php.net/manual/en/book.pdo.php https://www.grafikart.fr/tutoriels/pdo-php-1141 http://fmaz.developpez.com/tutoriels/php/comprendre-pdo/ https://openclassrooms.com/courses/les-transactions-avec-mysql-et-pdo http://sdz.tdct.org/sdz/do-comprendre-et-corriger-les-erreurs-les-plus-frequentes.html http://wiki.hashphp.org/PDO_Tutorial_for_MySQL_Developers http://micmap.org/php-by-example/fr/function/pdo https://www.w3schools.com/php/showphpfile.asp?filename=demo_db_select_pdo https://www.codeofaninja.com/2011/12/php-and-mysql-crud-tutorial.html https://phppot.com/php/creating-object-oriented-crud-system-using-php-and-mysql/ Tutos Vidéos Ajax Crud with JQuery Datatables by using PHP PDO PHP PDO grafikart PDO - CRUD avec php pdo et bootstrap / Aziz DAAIF Emmanuel Ravrat div. tutos create read update delete (CRUD) in php and mysql using Php Data Object (pdo) / polodev En attendant PDO C'est presque du Beckett… Une librairie pour autoriser des fonctions mysql_ php5 sur du php7: PHP 7 Shim for ext/mysql info/pdo/homepage.txt Dernière modification : 2023/01/13 09:57de 216.244.66.245 S'identifier