Guest Posted August 2, 2020 Share Posted August 2, 2020 works. Thank you very much Quote Link to comment https://forums.phpfreaks.com/topic/311255-error-converting-mysqli-to-pdo/page/2/#findComment-1580262 Share on other sites More sharing options...
jodunno Posted August 2, 2020 Share Posted August 2, 2020 hello, i really have no time to code it for you. i need to mention that my last post needs to be adjusted by you. the query needs to be changed from columns to all if you wish to fill the variables correctly. so $query = 'SELECT convoy_name, convoy_organizer FROM convoys where id = :getId'; needs to be $query = 'SELECT * FROM convoys where id = :getId'; you take things to literally and i have no time to be perfect. i need to go for now. Quote Link to comment https://forums.phpfreaks.com/topic/311255-error-converting-mysqli-to-pdo/page/2/#findComment-1580263 Share on other sites More sharing options...
jodunno Posted August 2, 2020 Share Posted August 2, 2020 Just now, Endrick said: works. Thank you very much oh, yay! i am happy for you! good work! Thank you for putting forth the effort. Best wishes. Quote Link to comment https://forums.phpfreaks.com/topic/311255-error-converting-mysqli-to-pdo/page/2/#findComment-1580264 Share on other sites More sharing options...
Guest Posted August 2, 2020 Share Posted August 2, 2020 @jodunno finally can you help me quickly with that $s2 = $bdd->query("SELECT * FROM convoy_part WHERE user_convoy= :I"); $start = $bdd->prepare($s2); $start->execute(array(':I' => $_GET['id'])); Quote Link to comment https://forums.phpfreaks.com/topic/311255-error-converting-mysqli-to-pdo/page/2/#findComment-1580266 Share on other sites More sharing options...
jodunno Posted August 2, 2020 Share Posted August 2, 2020 so this is not correctly formed. I wish i knew how to describe the variables accurately but i do not know how to do so. let's try it this way and see if it makes sense: you need to define a way to connect to the database using pdo. thus $bdd = new PDO (); you can name this variable whatever you want to name it. $80s_rocker_still_rockin_but_missing_me_long_hair = new PDO(). get it? then you need a query, which can be called whatever you want it to be called. such as $qry, $query, $scorpions_bad_boys_running_wild. who cares about the name. The concept is important here: $jodunno_nuthin = 'SELECT * FROM convoy_part WHERE user_convoy= :I"; you are actually going to 'prepare' this query for execution. then you use another variable named anything that you want to represent the database actions being performed. $s2, $start, $kix_blow_my_fuse or whatever. $gnr_nighttrain = new PDO("bla blah", more-blah , blah); $jodunno_nuthin = 'SELECT * FROM convoy_part WHERE user_convoy= :I"; $load_the_cannons = $gnr_nighttrain->prepare($jodunno_nuthin); $load_the_cannons->execute(array(':I' => $_GET['id'])); $db_is_shooting_back = $load_the_cannons->fetch(); put it all together in one sensical operation. so let's light the cannons and fire: $query = "SELECT * FROM convoy_part WHERE user_convoy= :I'; $start = $bdd->prepare($query); $start->execute(array(':I' => $_GET['id'])); then perform your fetch. think of a dog chasin' a stick: fetch boy! $result = $start->fetch(); naming variables really doesn't matter when you are practicing code. understanding variables is 'sehr wichtig'. keep it all sensical, logical and easy to understand when you look at the code 5 years from now. The idea is to understand what $bdd represents and what $query represents, etc. you are often times getting lost and mixing variable names as if you don't understand what is happening. stay focused! Best wishes. Quote Link to comment https://forums.phpfreaks.com/topic/311255-error-converting-mysqli-to-pdo/page/2/#findComment-1580268 Share on other sites More sharing options...
Guest Posted August 2, 2020 Share Posted August 2, 2020 https://prnt.sc/tsp8tt whats wrong here. The list get the data from this code $query = 'SELECT * FROM convoy_part WHERE user_convoy= :I'; $start = $bdd->prepare($query); $start->execute(array(':I' => $_GET['id'])); $result2 = $start->fetch(); Quote Link to comment https://forums.phpfreaks.com/topic/311255-error-converting-mysqli-to-pdo/page/2/#findComment-1580278 Share on other sites More sharing options...
Barand Posted August 2, 2020 Share Posted August 2, 2020 8 hours ago, jodunno said: so $query = 'SELECT convoy_name, convoy_organizer FROM convoys where id = :getId'; needs to be $query = 'SELECT * FROM convoys where id = :getId'; That is one of the worse pieces of advice I have seen in these forums for a long time. @Endrick, ignore what @jodunno said in the above quote and specify the columns your query needs - don't use "SELECT * ". One day it will come back to bite you. Consider this scenario... Joe has written a script which creates a register of all student names, and uses "SELECT * FROM student" (with the excuse that he needs all the columns anyway) and iterates through the results. He then takes a holiday and, while he is away, things change. A colleague of his adds a new "dissertation" column and an image BLOB column to the student table. This contains the text of each student's 10,000 word final dissertation and a photo of the student. His register program still works but a query that took milliseconds now takes an age to run. The register doesn't need the dissertation or image data but, nevertheless, is dragging them down from the database for every student. 1 Quote Link to comment https://forums.phpfreaks.com/topic/311255-error-converting-mysqli-to-pdo/page/2/#findComment-1580287 Share on other sites More sharing options...
Guest Posted August 2, 2020 Share Posted August 2, 2020 6 hours ago, Endrick said: https://prnt.sc/tsp8tt was hier falsch ist. Die Liste erhält die Daten aus diesem Code ok changed it but can someone help me with this problem in the quote Quote Link to comment https://forums.phpfreaks.com/topic/311255-error-converting-mysqli-to-pdo/page/2/#findComment-1580289 Share on other sites More sharing options...
jodunno Posted August 2, 2020 Share Posted August 2, 2020 On 8/1/2020 at 9:53 PM, jodunno said: 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. advice allready given. read entire thread b4 trolling. Quote Link to comment https://forums.phpfreaks.com/topic/311255-error-converting-mysqli-to-pdo/page/2/#findComment-1580290 Share on other sites More sharing options...
Guest Posted August 3, 2020 Share Posted August 3, 2020 On 8/2/2020 at 2:01 PM, jodunno said: so this is not correctly formed. I wish i knew how to describe the variables accurately but i do not know how to do so. let's try it this way and see if it makes sense: you need to define a way to connect to the database using pdo. thus $bdd = new PDO (); you can name this variable whatever you want to name it. $80s_rocker_still_rockin_but_missing_me_long_hair = new PDO(). get it? then you need a query, which can be called whatever you want it to be called. such as $qry, $query, $scorpions_bad_boys_running_wild. who cares about the name. The concept is important here: $jodunno_nuthin = 'SELECT * FROM convoy_part WHERE user_convoy= :I"; you are actually going to 'prepare' this query for execution. then you use another variable named anything that you want to represent the database actions being performed. $s2, $start, $kix_blow_my_fuse or whatever. $gnr_nighttrain = new PDO("bla blah", more-blah , blah); $jodunno_nuthin = 'SELECT * FROM convoy_part WHERE user_convoy= :I"; $load_the_cannons = $gnr_nighttrain->prepare($jodunno_nuthin); $load_the_cannons->execute(array(':I' => $_GET['id'])); $db_is_shooting_back = $load_the_cannons->fetch(); put it all together in one sensical operation. so let's light the cannons and fire: $query = "SELECT * FROM convoy_part WHERE user_convoy= :I'; $start = $bdd->prepare($query); $start->execute(array(':I' => $_GET['id'])); then perform your fetch. think of a dog chasin' a stick: fetch boy! $result2 = $start->fetch(); naming variables really doesn't matter when you are practicing code. understanding variables is 'sehr wichtig'. keep it all sensical, logical and easy to understand when you look at the code 5 years from now. The idea is to understand what $bdd represents and what $query represents, etc. you are often times getting lost and mixing variable names as if you don't understand what is happening. stay focused! Best wishes. I think you get me wrong, the list has a problem getting the data from the one in the quote. Code of List: <table class="table"> <thead> <tr> <th scope="col">#</th> <th scope="col">User</th> <th scope="col">Datum</th> <th scope="col"><a class="btn btn-primary" href="convoy_user.php?id=<?php echo $result2['user_convoy']; ?>&action=part" role="button">Teilnehmen</a></th> </tr> </thead> <tbody> <?php while($result2 = $start->fetch()){ ?> <tr> <th scope="row"><?php echo $result2['id']; ?></th> <td><?php echo $result2['name']; ?></td> <td><?php echo $result2['date']; ?></td> </tr> <?php } ?> </tbody> </table> Quote Link to comment https://forums.phpfreaks.com/topic/311255-error-converting-mysqli-to-pdo/page/2/#findComment-1580312 Share on other sites More sharing options...
Guest Posted August 5, 2020 Share Posted August 5, 2020 On 8/3/2020 at 3:01 PM, Endrick said: I think you get me wrong, the list has a problem getting the data from the one in the quote. Code of List: <table class="table"> <thead> <tr> <th scope="col">#</th> <th scope="col">User</th> <th scope="col">Datum</th> <th scope="col"><a class="btn btn-primary" href="convoy_user.php?id=<?php echo $result2['user_convoy']; ?>&action=part" role="button">Teilnehmen</a></th> </tr> </thead> <tbody> <?php while($result2 = $start->fetch()){ ?> <tr> <th scope="row"><?php echo $result2['id']; ?></th> <td><?php echo $result2['name']; ?></td> <td><?php echo $result2['date']; ?></td> </tr> <?php } ?> </tbody> </table> Do anyone have an idea how can i fix this Quote Link to comment https://forums.phpfreaks.com/topic/311255-error-converting-mysqli-to-pdo/page/2/#findComment-1580367 Share on other sites More sharing options...
Barand Posted August 5, 2020 Share Posted August 5, 2020 On 8/2/2020 at 9:32 PM, jodunno said: table name: convoys columns: id, user_id, convoy_name, convoy_organizer then <?php echo $result2['user_convoy']; ?> and <td><?php echo $result2['name']; ?></td> <td><?php echo $result2['date']; ?></td> Where are those values (user_convoy, name and date) supposed to come from? Quote Link to comment https://forums.phpfreaks.com/topic/311255-error-converting-mysqli-to-pdo/page/2/#findComment-1580387 Share on other sites More sharing options...
Guest Posted August 6, 2020 Share Posted August 6, 2020 (edited) $query = 'SELECT * FROM convoy_part WHERE user_convoy= :I'; $start = $bdd->prepare($query); $start->execute(array(':I' => $_GET['id'])); $result2 = $start->fetch(); <div class="col-lg-12"> <div class="block margin-bottom-sm"> <div class="table-responsive"> <table class="table"> <thead> <tr> <th scope="col">#</th> <th scope="col">User</th> <th scope="col">Datum</th> <th scope="col"><a class="btn btn-primary" href="convoy_user.php?id=<?php echo $result2['user_convoy']; ?>&action=part" role="button">Teilnehmen</a></th> </tr> </thead> <tbody> <?php while($result2 = $start->fetch()){ ?> <tr> <th scope="row"><?php echo $result2['id']; ?></th> <td><?php echo $result2['name']; ?></td> <td><?php echo $result2['date']; ?></td> </tr> <?php } ?> </tbody> </table> Edited August 6, 2020 by Guest Quote Link to comment https://forums.phpfreaks.com/topic/311255-error-converting-mysqli-to-pdo/page/2/#findComment-1580405 Share on other sites More sharing options...
Guest Posted August 6, 2020 Share Posted August 6, 2020 https://prnt.sc/tv3vpm thats my datatable Quote Link to comment https://forums.phpfreaks.com/topic/311255-error-converting-mysqli-to-pdo/page/2/#findComment-1580406 Share on other sites More sharing options...
Guest Posted August 6, 2020 Share Posted August 6, 2020 (edited) - Edited August 6, 2020 by Guest Quote Link to comment https://forums.phpfreaks.com/topic/311255-error-converting-mysqli-to-pdo/page/2/#findComment-1580408 Share on other sites More sharing options...
Guest Posted August 6, 2020 Share Posted August 6, 2020 i fixed it Quote Link to comment https://forums.phpfreaks.com/topic/311255-error-converting-mysqli-to-pdo/page/2/#findComment-1580409 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.