Previously we changed the index page here to use pto instead of my ask you a lie.
Let's do the same with the individual article page.
The first thing we're doing in the article page is getting the database connection using the get d.b.
function which returns my Eskew allied database connection object in the index page that we changed
to use PDA although we create a new database object.
Then Karl they get canned method on it to get the connection.
So that's copy this
and replace the my.
ESKEW a lifeline
to use this class.
We need to require the file where the class is defined as we don't need this database include anymore
as this is where they get dbe function is we can replace this line to require the Database class instead.
Once we have the connection Will Carling they get article function which is defined in the includes
article that P HP P file here.
First we're creating a string variable that contains the ESC U L and as we using a prepared statement
we're inserting the idea of the article that we want with a place holder in my esky Well I place holders
in prepared statements.
Question mark characters in PD so you can use question marks as place holders too but you can also use
named parameters.
This is one of the advantages pdl has over my esky Well I.
So let's change this from a question mark to a named parameter which is a colon followed by a label
of your choice using named parameters makes the ESC u l much easier to read especially if you have several
parameters in it.
Then as with my ESC you a lie.
We prepare the statement by calling the prepare method on the connection object passing in the Eskew
L string.
Next we're not going to check if the statement is false as if there's an error.
An exception will be thrown which will deal with later so we can remove this.
Like that.
Next we need to bind a value to the parameter in the ESC u l string in PD So we call the bind value
method on the statement object passing in the named parameter the value and the type.
This is also where it's easier with named parameters as it's easier to see the value you're assigning
to each perimeter.
As father datatype this is one of these pdl class Constance billion integer string and so on.
The I.D. is an integer.
So we use that class constant to execute to Pedia prepared statement we call the execute method on the
statement object.
Then if this returns true we need to get the results.
This is also easier in PD 0.
Then in my Eskew ally we can replace these two.
My Escuela aligns with one line of pdl where we call the fetch method on the statement object.
This clearly shows the basic steps of a prepared statement.
Prepare.
Execute.
Fetch.
As with my esky Well I code we want an associative array of data so we pass in the fetch a SAQ class
constant.
Like that.
Let's try that out.
If I click on an article to view the individual article page then this works just as before.
Let's see what happens if I supply an I.D. of a rijkaard that doesn't exist.
We no longer get the article not found message that we did before.
This is because the pdaf fetch method returns false.
If no records are found but were checking for it being null in the article script we can simplify this
code by changing this if and swapping the if and else blocks like that.
Now if the article variable contains anything other than false are null the data will be displayed.
Otherwise we'll get the not found message.
So now if we have a valid I.D. We see the details.
But if we don't we get the not found message.