PHP Data Objects (PDO): Connecting (Part 1/8)

Codecourse · 171K views · 2014 · 11:31

Open on YouTube

Web developmentPython, Ruby & scripting languagesDatabases & storagetutorialdated

Why Stack Overflow recommends it

Stack Overflow users link it when telling askers to stop using the deprecated mysql_connect functions and switch to PDO for database access.

Recommended by 2 people across 2 different months, 2014 to 2016.

What it is

The first of an eight-part Codecourse tutorial series on PHP Data Objects (PDO), covering how to connect to a database from PHP. It is a screencast-style walkthrough aimed at PHP developers moving away from the old mysql_* functions.

What people said

Recommends Andrei P. · 2015-02 · Stack Overflow · on “trying to cretae a login using php”

Here's something that will keep you busy and you may learn something along the way. Let's take it step by step, or rather line by line. <?php include 'connection.php'; if(isset($_POST['Login'])) { $mail = $_POST['email']; $pwd = $_POST['password']; $query="SELECT email,password FROM fb_log"; $result=mysql_query($query); while($data=mysql_fetch_array($result)) { if($mail==$data['email'] && $pwd==$data['password']) { $_SESSION['email'] = $mail; $_SESSION['password'] = $pwd; header("location:home.php"); } else { header("location:bhag.php"); } } } ?> $query="SELECT email,password FROM fb_log"; This is where your main problem lies. As it stands this query will return all the emails and passwords

Recommends J. Robinson · 2016-08 · Stack Overflow · on “My data is not sended to database through PHP”

You should be using PDO instead of mysql_connect as it has been deprecated as of PHP 5.5.0. Please view this tutorial on how to use PDO. Here's more information about it: [LINK] [this video] As for your code just displaying on your screen, make sure that your server has php enabled.

Cites Dominic Farolino · 2014-12 · Stack Overflow · on “Logout button does not appear after user logs in”

Solution and Critique I don't quite understand why all of the login, registration, and logout information is on the same page however if you want it this way you'll have to add PHP conditionals managing what gets shown when certain session material is set. I would assume that the conditional you are talking about because the logout stuff is not showing would be around this area: <li class="left"> </li> <?php if $_SESSION['logged_in'] {?> <!-- Logout --> <li>Hello, <?php echo $_SESSION['email'] ?></li> <li><a href="logout.php">Log Out</a></li> <li class="sep">|</li> ...<?php } ?> <?php else { ?> <!--Things to show when user is not logged in--> <?php } ?> Please use PDO It is highly recommende