pdo

How to INSERT based on a condition?

。_饼干妹妹 提交于 2019-12-25 18:33:19
问题 I have these INSERT query: $db->prepare("INSERT INTO events (post_id, table_code, other_id, user_id, author_id, date_time ) VALUES (? , 15 , ? , ? , ? , UNIX_TIMESTAMP()), (? , 15 , ? , ? , ? , UNIX_TIMESTAMP()) ")->execute(array($answer_id, $answer_id, $author_ques_id, $author_ques_id, $answer_id, $answer_id, $author_ques_id, $author_ans_id)); As you see, query above inserts two rows into events table. Now I need to put a condition on the way of second row. I mean if $condition is true then

I need to nest 2 arrays so that I can echo order header as well as order item details

谁都会走 提交于 2019-12-25 17:44:51
问题 I have updated my original post based on what I learned from your comments below. It is a much simpler process than I originally thought. require '../database.php'; $pdo = Database::connect(); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $sql = "SELECT * FROM Orders WHERE id = 430"; $q = $pdo->prepare($sql); $q->execute(array($id)); $data = $q->fetch(PDO::FETCH_ASSOC); echo 'Order Num: ' . $data['id'] . '<br>'; $sql = "SELECT * FROM Order_items JOIN Parts ON Parts.id = Order

I need to nest 2 arrays so that I can echo order header as well as order item details

流过昼夜 提交于 2019-12-25 17:44:14
问题 I have updated my original post based on what I learned from your comments below. It is a much simpler process than I originally thought. require '../database.php'; $pdo = Database::connect(); $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $sql = "SELECT * FROM Orders WHERE id = 430"; $q = $pdo->prepare($sql); $q->execute(array($id)); $data = $q->fetch(PDO::FETCH_ASSOC); echo 'Order Num: ' . $data['id'] . '<br>'; $sql = "SELECT * FROM Order_items JOIN Parts ON Parts.id = Order

PHP PDO Error - : Invalid parameter number

烂漫一生 提交于 2019-12-25 17:40:06
问题 I'm trying to insert into a database for the first time using PDO but I keep getting the error Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: parameter was not defined' on line 25 Google tells me there is a mis match somewhere with the values I'm inserting but from what I can tell they add up $db = new PDO("mysql:host=$servername;dbname=$dbname",$username,$password); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $stmt =

Replace first instance NULL or ' ' with another value - MySQL [closed]

旧巷老猫 提交于 2019-12-25 17:19:42
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago . I'm trying to replace the first instance of a NULl or ' ' value in a column with another value. But only the first instance and nothing else. So far I've put this together: UPDATE table_name SET column = CONCAT(REPLACE(LEFT(column , INSTR(column , '')), '', 'new_value'), SUBSTRING(column , INSTR(column , '') +1)

MySQL PDO query LIKE with PIPES

主宰稳场 提交于 2019-12-25 17:15:25
问题 I have a PDO statement which is supposed to look for data with pipes around it, I have multiple id's stored in a single column. I know this isn't great but it seems the logical way to store the data. Column content example |1|3|4|5|14|76| So I want to find every line in the database with 3 in it. I use a php form to post or get 3 $getthis = $_GET['getthis']; $sql = "SELECT * FROM table WHERE types LIKE '?' ORDER BY name"; $q = $conn->prepare($sql); $q->execute('%|$getthis|%'); while ($data =

PDO Prepared Statement Execution - How to get only associative keys?

删除回忆录丶 提交于 2019-12-25 17:09:06
问题 This should be a simple thing to solve... I have got these estatements when a user logs in: $query = $conn->prepare("SELECT * FROM admins WHERE username = :user AND password = :pass"); $query->bindValue(":user", $user); $query->bindValue(":pass", md5($pass)); $query->execute(); Now if the user exists, I return the user information from the database, but if not, I return false instead... if($query->rowCount() > 0) { $admininfo = $query->fetchAll(PDO::FETCH_ASSOC); } else { return false; } But

link going through tracking script pulls correct article id, incorrect article text

只愿长相守 提交于 2019-12-25 16:51:26
问题 I have a page that displays content from different database tables. Each of the sections has a link in it to lead to a page (view_article.php, for example) where that content is displayed with its' comment section below it. The link in question being; '<a href="'.$site.'/views/track.php?id='.$row['article_id'].'"> <font face="arial black" color="#0000CC" size="5"> Click Here For Full Story </font> </a> <hr>'; I know there's something I'm completely missing as this link works correctly for me

Best practices accessing a logged in User object from other classes [closed]

六月ゝ 毕业季﹏ 提交于 2019-12-25 16:47:04
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 5 years ago . This is a question regarding best practice for storing and accessing an object from another class. I'm using a simple homemade MVC paradigm in PHP , the class is called User and has its own methods and vars that essentially works as a database abstraction layer. This class is

PDO Querying database through sessions

冷暖自知 提交于 2019-12-25 16:44:56
问题 I am trying to call data from my database to display on a users profile. I have the user session working correctly in the check user file. However the code below obviously isn; retrieving anything because it won't echo out in the echo statment i have in my HTML. Can someone please help??? require_once 'check.php'; if(isset($_GET['full_name'])){ $full_name = $_GET['full_name']; $username = $_GET['username']; $country = $_GET['country']; $bio = $_GET['bio']; $stmt = $dtb->prepare(" SELECT full