[Solved] Why if…else stop working after I switched to DBO? [closed]

It is not whatever “DBO” but the code you wrote. Although I managed to get it’s meaning only after reformatting it sanely. Here it goes: $select_links = “SELECT * FROM $table”; if (isset($_POST[‘link’])) { if ($_POST[‘link’] == ‘0’){ // do nothing } } else { $links = $conn->prepare($select_links); $links->execute(); $links->setFetchMode(PDO::FETCH_ASSOC); while($row1 = $links->fetch()) { echo … Read more

[Solved] PDO in PHP doesn´t work – no error

In addition to what @Niet Suggested you have to know that you cannot reuse the same name for the placeholder like you did: INSERT INTO veranstaltung_anfrage (….) VALUES (..:a, :a, :a, :a, :a, :a, :a) You will need to give them unique names: INSERT INTO veranstaltung_anfrage (….) VALUES (..:a1, :a2, :a3, :a4, :a5….) then bind … Read more

[Solved] PDO Query throws a fatal error saying bound variables does not match number of tokens [closed]

The error is with this code. You are binding the params to different query object. $addTl = “UPDATE teams SET tlName = :tlName, tlSet = :tlSet WHERE tId = :tId”; $addTlQuery = $dbConnect -> prepare($addTl); $addUserQuery -> bindParam(‘:tId’, $_REQUEST[“team”]); $addUserQuery -> bindParam(‘:tlName’, $lastUid); $addUserQuery -> bindParam(‘:tlSet’, $_REQUEST[“tl”]); echo $lastUid. ” Last ID<br>”; echo $_REQUEST[“tl”]. ” … Read more

[Solved] PHP: Passing row values into form to edit

You’re mixing named parameters with variables. You are also not binding the variable to the query. Since you’re not using raw PDO, it will obviously vary a little bit, but here’s what you would do if you were. You’ll just have to adapt it to your $event object: $stmt = $dbh->prepare( “SELECT event_name, event_description, event_category, … Read more

[Solved] Parameterized SELECT queries via PDO? [duplicate]

The PHP Manual has some good examples. For you: function user_login($username, $password) { $conn = connection_getConnection(); $sql = “SELECT `password` FROM `users` WHERE `username` = :username”; $stmt = $conn->prepare($sql, array(PDO::ATTR_CURSOR => PDO::CURSOR_FWDONLY)); $query = $stmt->execute(array(‘:username’ => $username)); $rows = $query->fetchAll(); if (empty($rows)) { } } 5 solved Parameterized SELECT queries via PDO? [duplicate]

[Solved] Fatal error: Uncaught Error: Call to a member function fetch() on boolean in #0 {main} thrown in on line 7 [duplicate]

Your PDO constructor is wrong. You are not declaring the database to which the PDO instance should connect to. $db = new PDO(‘mysql:host=localhost;root’, ‘test’, ”); The DSN should have the database name and the host name. You have root at the end of it which should not be there. The line above should be like … Read more

[Solved] Html / php not updating sql database [duplicate]

Your if-statement checks !empty($_POST[‘doa’]), but your form does not contain a doa: <label for=”doa”>Date of Admission:</label> <input type=”text” name=”dob”> This <input> should probably have name=”doa” instead of dob. 3 solved Html / php not updating sql database [duplicate]

[Solved] PDO Insert error on execute

Looks like your DSN is incorrect (you have a space in it). Try this PDO constructor and stop using or die()! $db = new PDO(‘mysql:host=localhost;dbname=xxxxxx;charset=utf8’, ‘yyyyyy’, ‘zzzzzz’, array( PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC)); $query = “INSERT INTO multiTicker (mtgox,btcstamp,btce,btcchina,myDateTime) VALUES (:mtgox,:btcstamp,:btce,:btcchina,:myDateTime)”; $st = $db->prepare($query); $st->execute(array( ‘:mtgox’ => $mtgox, ‘:btcstamp’ => $btcstamp, … Read more

[Solved] Can I improve my PDO method (just started)

catch(PDOException $e) { echo ‘<p class=”error”>Database query error!</p>’; } I would use the opportunity to log which database query error occurred. See example here: http://php.net/manual/en/pdostatement.errorinfo.php Also if you catch an error, you should probably return from the function or the script. if ($STH) { // does this really need an if clause for it self? … Read more

[Solved] PDO table inside table using json

Start by returning objects from PDO as that is what you want. Then only select from the table the columns that you actually need Then build the data structure that you believe you want from the returned data $stmt1 = $db->prepare(“SELECT title,description FROM data WHERE id=’1′”); $stmt1->execute(); $data = $stmt1->fetch(PDO::FETCH_OBJ); $stmt2 = $db->prepare(“SELECT id,title FROM … Read more

[Solved] Count elements with a the same name in an array in php

array_count_values array_count_values() returns an array using the values of array as keys and their frequency in array as values. $varArray = array(); // take a one empty array foreach ($rowa as $rowsa) { $sql = “SELECT count(*) as NUMBER FROM BANDZENDINGEN WHERE FB_AFGESLOTEN = ‘F’ AND FB_AKTIEF = ‘T’ AND FI_AFVOERKANAAL = 1 AND FI_RAYONID … Read more

[Solved] retrieve data from db using function pdo

Change the function to this: function run_db($sqlcom,$exe){ $conn = new PDO(‘mysql:host=localhost;dbname=dbname’, ‘usr’, ‘pass’); $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $stmt = $conn->prepare($sqlcom); $stmt->execute($exe); return $stmt; } and the call to that function to: try { $stmt = run_db(‘SELECT * FROM posts WHERE status= :published ORDER BY id DESC LIMIT 5’,array(‘:published’ => ‘published’)); while ($result = $stmt->fetch(PDO::FETCH_ASSOC)) { $contents = … Read more