Guest Posted August 1, 2020 Share Posted August 1, 2020 hello i tried to switch from mysqli to pdo but somehow i made a mistake MYSQLI $qry = "SELECT * FROM con where id= '$user'"; $result = mysqli_query($conn, $qry); while ($row = mysqli_fetch_assoc($result)) { print_r($row["convoy_cars"], true); if($row["convoy_cars"] == 1){ echo '<div class="dashtext-3">Autos für Spieler erlaubt: <a class="btn btn-sm primary rounded"><i class="fa fa-check-square"></div></i> </a>'; } elseif($row["convoy_cars"] == 2){ echo '<div class="dashtext-3">Autos für Spieler erlaubt: <a class="btn btn-sm danger rounded"><i class="fa fa-times"></i></div> </a>'; } print_r($row["convoy_hct"], true); if($row["convoy_hct"] == 1){ echo '<div class="dashtext-3">HCT-Trailer erlaubt: <a class="btn btn-sm primary rounded"><i class="fa fa-check-square"></i> </div></a>'; } elseif($row["convoy_hct"] == 2){ echo '<div class="dashtext-3">HCT-Trailer erlaubt: <a class="btn btn-sm danger rounded"><i class="fa fa-times"></i></div> </a>'; print_r($row["convoy_absicherung"], true); } if($row["convoy_absicherung"] == 1){ echo '<div class="dashtext-3">Absicherung: <a class="btn btn-sm primary rounded"><i class="fa fa-check-square"></i> </div></a>'; } elseif($row["convoy_absicherung"] == 2){ echo '<div class="dashtext-3">Absicherung: <a class="btn btn-sm danger rounded"><i class="fa fa-times"></i></div> </a>'; } } my try in pdo $qry = "SELECT * FROM con where id= '$user'"; $result = $pdo->prepare($qry); while ($row = $qry->fetch(PDO::FETCH_ASSOC)){ print_r($row["convoy_cars"], true); if($row["convoy_cars"] == 1){ echo '<div class="dashtext-3">Autos für Spieler erlaubt: <a class="btn btn-sm primary rounded"><i class="fa fa-check-square"></div></i> </a>'; } elseif($row["convoy_cars"] == 2){ echo '<div class="dashtext-3">Autos für Spieler erlaubt: <a class="btn btn-sm danger rounded"><i class="fa fa-times"></i></div> </a>'; } print_r($row["convoy_hct"], true); if($row["convoy_hct"] == 1){ echo '<div class="dashtext-3">HCT-Trailer erlaubt: <a class="btn btn-sm primary rounded"><i class="fa fa-check-square"></i> </div></a>'; } elseif($row["convoy_hct"] == 2){ echo '<div class="dashtext-3">HCT-Trailer erlaubt: <a class="btn btn-sm danger rounded"><i class="fa fa-times"></i></div> </a>'; print_r($row["convoy_absicherung"], true); } if($row["convoy_absicherung"] == 1){ echo '<div class="dashtext-3">Absicherung: <a class="btn btn-sm primary rounded"><i class="fa fa-check-square"></i> </div></a>'; } elseif($row["convoy_absicherung"] == 2){ echo '<div class="dashtext-3">Absicherung: <a class="btn btn-sm danger rounded"><i class="fa fa-times"></i></div> </a>'; } } Quote Link to comment https://forums.phpfreaks.com/topic/311255-error-converting-mysqli-to-pdo/ Share on other sites More sharing options...
ginerjm Posted August 1, 2020 Share Posted August 1, 2020 These two lines: $result = $pdo->prepare($qry); while ($row = $qry->fetch(PDO::FETCH_ASSOC)) are the problem. The first creates a "statement" var so you could call it something like $stmt instead of result. Then you have to actually execute the prepared statement/query before you try and fetch something. Once you have done that you will be better off. Try looking at an example in the official PHP manual to get a better idea. Quote Link to comment https://forums.phpfreaks.com/topic/311255-error-converting-mysqli-to-pdo/#findComment-1580214 Share on other sites More sharing options...
Guest Posted August 1, 2020 Share Posted August 1, 2020 Thank you for your contribution, but you could give an example using my code Quote Link to comment https://forums.phpfreaks.com/topic/311255-error-converting-mysqli-to-pdo/#findComment-1580215 Share on other sites More sharing options...
jodunno Posted August 1, 2020 Share Posted August 1, 2020 (edited) Hello, i think that any community should be willing to facilitate migration from mysqli to pdo. Thus, i am stepping up to offer support. here is an example of the necessary code to conduct pdo business as usual. i use variables when executing queries but bindings can also be used. I use a variable to set necessary attributes. I've included association to make life easier. $host = 'localhost'; //localhost or 127.0.0.1 $yourdbnamevar = 'mytestdb'; $your_db_username = 'root'; $your_db_password = ''; $attributes = array( PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC ); $connection = new PDO("mysql:host=$host; dbname=$yourdbnamevar; charset=utf8mb4", $your_db_username, $your_db_password, $attributes); $qry = 'SELECT * FROM con where id = :user'; $start = $connection->prepare($qry); $start->execute(array(':user' => $user)); $result = $start->fetch(); I hope that this code helps you migrate successfully. Best wishes! Edited August 1, 2020 by jodunno spelling error Quote Link to comment https://forums.phpfreaks.com/topic/311255-error-converting-mysqli-to-pdo/#findComment-1580216 Share on other sites More sharing options...
Guest Posted August 1, 2020 Share Posted August 1, 2020 somehow it doesn't work require('connection/db1.php'); $qry = 'SELECT * FROM con where id = :user'; $start = $bdd->prepare($qry); $start->execute(array(':user' => $user)); $result = $start->fetch(); print_r($row["convoy_cars"], true); if($row["convoy_cars"] == 1){ echo '<div class="dashtext-3">Autos für Spieler erlaubt: <a class="btn btn-sm primary rounded"><i class="fa fa-check-square"></div></i> </a>'; } elseif($row["convoy_cars"] == 2){ echo '<div class="dashtext-3">Autos für Spieler erlaubt: <a class="btn btn-sm danger rounded"><i class="fa fa-times"></i></div> </a>'; } print_r($row["convoy_hct"], true); if($row["convoy_hct"] == 1){ echo '<div class="dashtext-3">HCT-Trailer erlaubt: <a class="btn btn-sm primary rounded"><i class="fa fa-check-square"></i> </div></a>'; } elseif($row["convoy_hct"] == 2){ echo '<div class="dashtext-3">HCT-Trailer erlaubt: <a class="btn btn-sm danger rounded"><i class="fa fa-times"></i></div> </a>'; print_r($row["convoy_absicherung"], true); } if($row["convoy_absicherung"] == 1){ echo '<div class="dashtext-3">Absicherung: <a class="btn btn-sm primary rounded"><i class="fa fa-check-square"></i> </div></a>'; } elseif($row["convoy_absicherung"] == 2){ echo '<div class="dashtext-3">Absicherung: <a class="btn btn-sm danger rounded"><i class="fa fa-times"></i></div> </a>'; } db1.php <?php $bdd = new PDO('mysql:host=localhost;dbname=;charset=utf8', '', ''); ?> Quote Link to comment https://forums.phpfreaks.com/topic/311255-error-converting-mysqli-to-pdo/#findComment-1580217 Share on other sites More sharing options...
jodunno Posted August 1, 2020 Share Posted August 1, 2020 6 minutes ago, Endrick said: somehow it doesn't work $result = $start->fetch(); print_r($row["convoy_cars"], true); if you want to use $row instead of $result, then change the code. $result['convoy_cars'] will display the column data. Take the example pdo code that i have posted and make it work with your existing code. remember to use corresponding names of variables and arrays. Quote Link to comment https://forums.phpfreaks.com/topic/311255-error-converting-mysqli-to-pdo/#findComment-1580218 Share on other sites More sharing options...
Guest Posted August 1, 2020 Share Posted August 1, 2020 Thank you works great maybe you can help me with this if (isset($_GET['id'])) { $user = mysqli_real_escape_string($conn , $_GET['id']); $query = "SELECT * FROM con WHERE id= '$user' "; $run_query = mysqli_query($conn, $query) or die(mysqli_error($conn)) ; if (mysqli_num_rows($run_query) > 0 ) { while ($row = mysqli_fetch_array($run_query)) { $convoy_name = $row['convoy_name']; $convoy_veranstalter = $row['convoy_veranstalter']; $convoy_server = $row['convoy_server']; $convoy_date = $row['convoy_date']; $convoy_adddate = $row['convoy_adddate']; $convoy_language = $row['convoy_language']; $convoy_participants = $row['convoy_participants']; $convoy_route = $row['convoy_route']; $convoy_description = $row['convoy_description']; $convoy_kilometer = $row['convoy_kilometer']; $convoy_web_social = $row['convoy_web_social']; } } else { $convoy_name = "N/A"; $convoy_veranstalter = "N/A"; $convoy_server = "N/A"; $convoy_date = "N/A"; $convoy_adddate = "N/A"; $convoy_language = "N/A"; $convoy_participants = "N/A"; $convoy_route = "N/A"; $convoy_description = "N/A"; $convoy_kilometer = "N/A"; $convoy_web_social = "N/A"; } } Quote Link to comment https://forums.phpfreaks.com/topic/311255-error-converting-mysqli-to-pdo/#findComment-1580219 Share on other sites More sharing options...
jodunno Posted August 1, 2020 Share Posted August 1, 2020 also, db1.php has insufficient data for making a connection. $bdd = new PDO('mysql:host=localhost;dbname=;charset=utf8', '', ''); let's pretend that your database is name 'mytestdb' and your database username is 'root' and your password is empty (default empty using xampp). $host = 'localhost'; $yourdbnamevar = 'mytestdb'; $your_db_username = 'root'; $your_db_password = ''; $attributes = array( PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC ); $bdd = new PDO("mysql:host=$host; dbname=$yourdbnamevar; charset=utf8mb4", $your_db_username, $your_db_password, $attributes); be sure to include host, database name, character set if you need it followed by the actual db username, password and attributes. as for your last post, have you tried the following approach? $result = $start->fetch(); $convoy_name = $result['convoy_name']; $convoy_veranstalter = $result['convoy_veranstalter']; $convoy_server = $result['convoy_server']; $convoy_date = $result['convoy_date']; $convoy_adddate = $result['convoy_adddate']; $convoy_language = $result['convoy_language']; $convoy_participants = $result['convoy_participants']; //you could also use closeCursor as a feel-good terminator $start=>closeCursor(); once you execute the fetch, then your data is available to you. Either set variables for each requested column or use loops. Quote Link to comment https://forums.phpfreaks.com/topic/311255-error-converting-mysqli-to-pdo/#findComment-1580220 Share on other sites More sharing options...
Guest Posted August 1, 2020 Share Posted August 1, 2020 doesn't quite work. I just send the code https://hastebin.com/utayizadey.xml Quote Link to comment https://forums.phpfreaks.com/topic/311255-error-converting-mysqli-to-pdo/#findComment-1580221 Share on other sites More sharing options...
jodunno Posted August 1, 2020 Share Posted August 1, 2020 Hello Endrick, please slow down and be certain that you are maintaining consistency in your variable names. you are using $s2 in place of $start. let's agree on names: $bdd, $query, $s2, $results. Then try the following code: <?php require('connection/db1.php'); // Abfragen der Daten z.B. für <?php echo $convoy_description; ... $bdd = new PDO("", ,); //fill in connection data and be sure that this data is available in db1.php $query = 'SELECT * FROM convoy_part WHERE user_convoy = :getID'; $s2 = $bdd->prepare($query); $s2->execute(array(':getID' => $_GET['id'])); //if you do not set fetch association in the attributes, then you must set it in your while loop while ($result = $s2->fetch(PDO::FETCH_ASSOC)) { $convoy_name = $result['convoy_name']; $convoy_veranstalter = $result['convoy_veranstalter']; $convoy_server = $result['convoy_server']; $convoy_date = $result['convoy_date']; $convoy_adddate = $result['convoy_adddate']; $convoy_language = $result['convoy_language']; $convoy_participants = $result['convoy_participants']; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/311255-error-converting-mysqli-to-pdo/#findComment-1580222 Share on other sites More sharing options...
Guest Posted August 1, 2020 Share Posted August 1, 2020 With this code i get whitescreen https://hastebin.com/adatohigek.xml Quote Link to comment https://forums.phpfreaks.com/topic/311255-error-converting-mysqli-to-pdo/#findComment-1580223 Share on other sites More sharing options...
jodunno Posted August 1, 2020 Share Posted August 1, 2020 you have the following code: <?php // Abrufen der ID für Teilnehmerknopf if (isset($_GET['id'])) { $user2 = mysqli_real_escape_string($conn , $_GET['id']); $query = "SELECT * FROM convoy_part WHERE id= '$user2' "; $run_query = mysqli_query($conn, $query) or die(mysqli_error($conn)) ; } ?> you should practice pdo in a new php file. write it out according to my example and examples on internet pages about pdo. when you see the expected results printed on the screen of your new php practice file, then you can begin integrating your webpage to the new pdo method of retrieving data from a db. Quote Link to comment https://forums.phpfreaks.com/topic/311255-error-converting-mysqli-to-pdo/#findComment-1580225 Share on other sites More sharing options...
Guest Posted August 1, 2020 Share Posted August 1, 2020 https://prnt.sc/tsd5jx so the page works partially now nothing is output Quote Link to comment https://forums.phpfreaks.com/topic/311255-error-converting-mysqli-to-pdo/#findComment-1580226 Share on other sites More sharing options...
Strider64 Posted August 1, 2020 Share Posted August 1, 2020 I personally would make the flow a little easier to follow: here's my example: /* * Database Connection * I would have the PDO database connection in a separate file (Something like inc.pdoConnect.php) * and then call it something like require_once "includes/inc.pdoConnect.php"; */ $db_options = [ /* important! use actual prepared statements (default: emulate prepared statements) */ PDO::ATTR_EMULATE_PREPARES => false /* throw exceptions on errors (default: stay silent) */ , PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION /* fetch associative arrays (default: mixed arrays) */ , PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC ]; $pdo = new PDO('mysql:host=' . DATABASE_HOST . ';dbname=' . DATABASE_NAME . ';charset=utf8', DATABASE_USERNAME, DATABASE_PASSWORD, $db_options); /* End of Connection String */ /* I would personally only be pulling out table column names instead of the wildcard * */ $query = "SELECT * FROM convoy_part WHERE us_convoy=:get_id"; $stmt = $pdo->prepare($query); $stmt->execute([':get_id' => $_GET['id']); // I personally would have something like uniform :convoy_id / $_GET['convoy_id] $result = $stmt->fetchALL(PDO::FETCH_ASSOC); echo "<pre>" . print_r($result, 1) . "</pre>"; // Great way to debug and see what is going on: /* I personally like using the fetch statement over the while statement */ foreach ($result as $results) { $convoy_name = $results['convoy_name']; $convoy_veranstalter = $results['convoy_veranstalter']; $convoy_server = $results['convoy_server']; $convoy_date = $results['convoy_date']; $convoy_adddate = $results['convoy_adddate']; $convoy_language = $results['convoy_language']; $convoy_participants = $results['convoy_participants']; } Make sure you have error reporting turned on ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL); It will help you debug your code easier. Quote Link to comment https://forums.phpfreaks.com/topic/311255-error-converting-mysqli-to-pdo/#findComment-1580227 Share on other sites More sharing options...
Guest Posted August 1, 2020 Share Posted August 1, 2020 (edited) i get this errors Notice: Undefined variable: convoy_description in Trying to access array offset on value of type bool in Edited August 1, 2020 by Guest Quote Link to comment https://forums.phpfreaks.com/topic/311255-error-converting-mysqli-to-pdo/#findComment-1580228 Share on other sites More sharing options...
Guest Posted August 1, 2020 Share Posted August 1, 2020 https://prnt.sc/tse19n something makes a problem in the code, because without $ stmt-> execute ([': get_id' => $ _GET ['id']); it looks like this https://prnt.sc/tse25q Quote Link to comment https://forums.phpfreaks.com/topic/311255-error-converting-mysqli-to-pdo/#findComment-1580230 Share on other sites More sharing options...
jodunno Posted August 1, 2020 Share Posted August 1, 2020 11 minutes ago, Endrick said: https://prnt.sc/tse19n something makes a problem in the code, because without $ stmt-> execute ([': get_id' => $ _GET ['id']); it looks like this https://prnt.sc/tse25q his code is missing the closing bracket: $stmt->execute([':get_id' => $ _GET ['id']]); which is why i use array (so that brackets are easy to see): $start->execute(array(':getId' => $_GET['id'])); really, you should use a practice file and select names that are consistent. either $start, $s2, $stmt or some other name but mixing names even in this thread is confusing. Quote Link to comment https://forums.phpfreaks.com/topic/311255-error-converting-mysqli-to-pdo/#findComment-1580233 Share on other sites More sharing options...
Guest Posted August 1, 2020 Share Posted August 1, 2020 (edited) I get again white screen Edited August 1, 2020 by Guest Quote Link to comment https://forums.phpfreaks.com/topic/311255-error-converting-mysqli-to-pdo/#findComment-1580234 Share on other sites More sharing options...
jodunno Posted August 1, 2020 Share Posted August 1, 2020 (edited) I strongly urge you to create a practice file. You have to integrate your code to the pdo format. You implemented pdo but you still have old mysqli statements left in the code which need to be removed. I wouldn't loop at all if you are only fetching all columns in one row. a loop is necessary if you need all columns from many rows. xampp is nice and easy to install. set up a simple database and create a php file to practice pdo. like so: database name: mytestdb table name: convoys columns: id, user_id, convoy_name, convoy_organizer $host = 'localhost'; $yourdbnamevar = 'mytestdb'; $your_db_username = 'root'; $your_db_password = ''; $attributes = array( PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC ); $fake_id = 1; $connection = new PDO("mysql:host=$host; dbname=$yourdbnamevar; charset=utf8mb4", $your_db_username, $your_db_password, $attributes); $query = 'SELECT convoy_name, convoy_organizer FROM convoys where id = :id'; $start = $connection->prepare($query); $start->execute(array(':id' => $fake_id)); $result = $start->fetch(); echo $result['convoy_name'] . '<br>' . $result['convoy_organizer']; Best wishes. Edited August 1, 2020 by jodunno mismatched table names Quote Link to comment https://forums.phpfreaks.com/topic/311255-error-converting-mysqli-to-pdo/#findComment-1580236 Share on other sites More sharing options...
Guest Posted August 1, 2020 Share Posted August 1, 2020 my code looks very similar but something must be wrong https://hastebin.com/daxesemuni.xml Quote Link to comment https://forums.phpfreaks.com/topic/311255-error-converting-mysqli-to-pdo/#findComment-1580237 Share on other sites More sharing options...
jodunno Posted August 1, 2020 Share Posted August 1, 2020 it seems to me that you are copying and pasting code from this thread without trying to understand the code. for example, you have the following code in your file: $query = "SELECT * FROM convoy_part WHERE us_convoy=:get_id"; $stmt = $pdo->prepare($query); $start->execute(array(':getId' => $_GET['id'])); $result = $stmt->fetchALL(PDO::FETCH_ASSOC); you don't even notice the difference between :get_id and :getId. (the underscore naming convention, by the way, is just more useless bytes added to the file) once again, remove the following code block from your file: <?php include 'connection/sql1.php'; // Abrufen der ID für Teilnehmerknopf if (isset($_GET['id'])) { $user2 = mysqli_real_escape_string($conn , $_GET['id']); $query = "SELECT * FROM convoy_part WHERE id= '$user2' "; $run_query = mysqli_query($conn, $query) or die(mysqli_error($conn)) ; } ?> do you not notice that the aforementioned codeblock contains mysqli code? in your code you echo $convoy_kilometer but where is this data coming from? where do you set a variable named $convoy_kilometer? last time i mention a practice file. I recommend that you make a new blank php file specifically for learning pdo. use your current file as a basis. Actually, just start frsh from the html body tag with a proper pdo code block. simply echo results to see it working, then build the rest of your page. you have enough pdo ammo to clean up your document. the rest is up to you. let us know when you get it working... Quote Link to comment https://forums.phpfreaks.com/topic/311255-error-converting-mysqli-to-pdo/#findComment-1580243 Share on other sites More sharing options...
Guest Posted August 2, 2020 Share Posted August 2, 2020 (edited) if I use this code in an other file, it comes ... https://prnt.sc/tslrop $host = 'localhost'; $yourdbnamevar = 'mytestdb'; $your_db_username = 'root'; $your_db_password = ''; $attributes = array( PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC ); $fake_id = 1; $connection = new PDO("mysql:host=$host; dbname=$yourdbnamevar; charset=utf8mb4", $your_db_username, $your_db_password, $attributes); $query = 'SELECT convoy_name, convoy_organizer FROM convoys where id = :id'; $start = $connection->prepare($query); $start->execute(array(':id' => $fake_id)); $result = $start->fetch(); echo $result['convoy_name'] . '<br>' . $result['convoy_organizer']; Edited August 2, 2020 by Guest Quote Link to comment https://forums.phpfreaks.com/topic/311255-error-converting-mysqli-to-pdo/#findComment-1580257 Share on other sites More sharing options...
jodunno Posted August 2, 2020 Share Posted August 2, 2020 1 hour ago, Endrick said: if I use this code in an other file, it comes ... https://prnt.sc/tslrop so you are saying that it works? you see the data pulled from the database? Quote Link to comment https://forums.phpfreaks.com/topic/311255-error-converting-mysqli-to-pdo/#findComment-1580258 Share on other sites More sharing options...
Guest Posted August 2, 2020 Share Posted August 2, 2020 yes it works now we just have to add it to my code Quote Link to comment https://forums.phpfreaks.com/topic/311255-error-converting-mysqli-to-pdo/#findComment-1580259 Share on other sites More sharing options...
jodunno Posted August 2, 2020 Share Posted August 2, 2020 we also have to deal with the missing code because php will not function correctly when it comes across an undefined variable or many undefined variables. I mentioned $convoy_kilometer not being set in an earlier post but today i see the code. I didn't see that code yesterday, so my apologies for missing this code. now that you have the data from the database, you need to integrate it into your code. You will use only this working code to retrieve the data. So your old attempts must not be included in the file anymore. replace your content with the working code then slowly rebuild the page to work with this code. a few working changes means you can speed up the process and finish the page. so if the code works, then start your new document like so: <?php session_start(); if (!isset($_SESSION['username'])) { die('<meta http-equiv="refresh" content="1; URL=">'); } ?> <!DOCTYPE html> <html> <head> <title></title> <meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="description" content=""> <meta name="viewport" content="width=device-width, initial-scale=1"><meta name="robots" content="all,follow"> <link rel="stylesheet" href="vendor/bootstrap/css/bootstrap.min.css"> <link rel="stylesheet" href="vendor/font-awesome/css/font-awesome.min.css"><link rel="stylesheet" href="css/font.css"> <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Muli:300,400,700"> <link rel="stylesheet" href="css/style.default.css" id="theme-stylesheet"> <link rel="stylesheet" href="css/custom.css"><link rel="shortcut icon" href="img/favicon.ico"> </head> <body> <?php require('connection/db1.php'); //db1.php should contain your db connection material. i've included it here to remind you that it is needed for db connection //remove this code if you have it set in db1.php. notice that we set PDO::FETCH_ASSOC so you don't need to do this in the fetch statement //start of removable code if it exists in db1.php $your_db_username = 'root'; $your_db_password = ''; $attributes = array( PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC ); //end of removable code if it exists in db1.php $connection = new PDO("mysql:host=$host; dbname=$yourdbnamevar; charset=utf8mb4", $your_db_username, $your_db_password, $attributes); $query = 'SELECT convoy_name, convoy_organizer FROM convoys where id = :getId'; $start = $connection->prepare($query); $start->execute(array(':getId' => $_GET['id'])); //are you sure that $_GET['id'] is set and not empty/contains valid data? //$count = $start->rowCount(); //i think that count should still work correctly but i've commented it out to avoid problems. $result = $start->fetch(); foreach ($result as $results) { $convoy_veranstalter = $result['convoy_veranstalter']; $convoy_server = $result['convoy_server']; $convoy_date = $result['convoy_date']; $convoy_adddate = $result['convoy_adddate']; $convoy_language = $result['convoy_language']; $convoy_participants = $result['convoy_participants']; $convoy_route = $result['convoy_route']; $convoy_description = $result['convoy_description']; $convoy_kilometer = $result['convoy_kilometer']; $convoy_web_social = $result['convoy_web_social']; } ?> <?php include 'includes/inc.navbar.php';?> <!-- Sidebar Navigation end--> <div class="page-content"> <div class="page-header"> <div class="container-fluid"> <h2 class="h5 no-margin-bottom">Dashboard</h2> </div> </div> <section class="no-padding-top no-padding-bottom"> <div class="container-fluid"> <div class="row"> <div class="col-md-3 col-sm-6"> <div class="statistic-block block"> <div class="progress-details d-flex align-items-end justify-content-between"> <div class="title"> <div class="icon"><i class="icon-user-1"></i></div><strong>Veranstalter:</strong> </div> <div class="dashtext-3"><?php if (isset($convoy_veranstalter)) { echo $convoy_veranstalter; } ?></div> </div> <div class="progress progress-template"> <div role="progressbar" style="width: 100%" aria-valuenow="30" aria-valuemin="0" aria-valuemax="100" class="progress-bar progress-bar-template dashbg-3"></div> </div> </div> </div> <div class="col-md-3 col-sm-6"> <div class="statistic-block block"> <div class="progress-details d-flex align-items-end justify-content-between"> <div class="title"> <div class="icon"><i class="icon-contract"></i></div><strong>Teilnehmer:</strong> </div> <div class="dashtext-3"><?php if (isset($count)) { echo $count; } ?></div> </div> <div class="progress progress-template"> <div role="progressbar" style="width: 100%" aria-valuenow="70" aria-valuemin="0" aria-valuemax="100" class="progress-bar progress-bar-template dashbg-3"></div> </div> </div> </div> <div class="col-md-3 col-sm-6"> <div class="statistic-block block"> <div class="progress-details d-flex align-items-end justify-content-between"> <div class="title"> <div class="icon"><i class="icon-paper-and-pencil"></i></div><strong>Kilometer</strong> </div> <div class="dashtext-3"><?php if (isset($convoy_kilometer)) { echo $convoy_kilometer; } ?></div> </div> <div class="progress progress-template"> <div role="progressbar" style="width: 100%" aria-valuenow="55" aria-valuemin="0" aria-valuemax="100" class="progress-bar progress-bar-template dashbg-3"></div> </div> </div> </div> <div class="col-md-3 col-sm-6"> <div class="statistic-block block"> <div class="progress-details d-flex align-items-end justify-content-between"> <div class="title"> <div class="icon"><i class="icon-writing-whiteboard"></i></div><strong>Server</strong> </div> <div class="dashtext-3"><?php if (isset($convoy_server)) { echo $convoy_server; } ?></div> </div> <div class="progress progress-template"> <div role="progressbar" style="width: 100%" aria-valuenow="35" aria-valuemin="0" aria-valuemax="100" class="progress-bar progress-bar-template dashbg-3"></div> </div> </div> </div> </div> </div> </section> <section class="no-padding-top"> <div class="container-fluid"> <div class="row"> <div class="col-lg-9"> <div class="block margin-bottom-sm"> <div class="title"><strong>Event Description:</strong></div> <?php echo $convoy_description;?> </div> </div> </div> <footer class="footer"> <div class="footer__block block no-margin-bottom"> <div class="container-fluid text-center"> <p class="no-margin-bottom">2020 © Your company. Design by <a href="https://bootstrapious.com/p/bootstrap-4-dark-admin">Bootstrapious</a>.</p> </div> </div> </footer> </div> </div> <!-- JavaScript files--> <script src="vendor/jquery/jquery.min.js"></script> <script src="vendor/popper.js/umd/popper.min.js"> </script> <script src="vendor/bootstrap/js/bootstrap.min.js"></script> <script src="vendor/jquery.cookie/jquery.cookie.js"> </script> <script src="vendor/chart.js/Chart.min.js"></script> <script src="vendor/jquery-validation/jquery.validate.min.js"></script> <script src="js/charts-home.js"></script> <script src="js/front.js"></script> </body> </html> replace echo variables with an if isset to avoid errors if a problem exists. let us know how it goes... Quote Link to comment https://forums.phpfreaks.com/topic/311255-error-converting-mysqli-to-pdo/#findComment-1580261 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.