- This topic is empty.
Viewing 6 posts - 1 through 6 (of 6 total)
Viewing 6 posts - 1 through 6 (of 6 total)
- The forum ‘Back End’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
I have a good idea of whats going on here but there sections of the following PHP code that i don’t fully understand so it would be great if someone could explain them to me in a direct manner so that its easier to understand.
`
try {
$user = "root";
$pass = "Jv9524500";
$db = "Practice";
$connect = new PDO("mysql:host=localhost; dbname=$db", $user, $pass);
$connect -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch( PDOException $e ) {
$e -> getMessage();
echo "Couldn't connect to the database";
die();
}
`
$connect -> setAttribute
} catch( PDOException $e ) {
new PDO
?
->
arrow is used to call a method on an object; in this case, the setAttribute
method on your PDO object.
try … catch
blocks for exception-based error handling. In basic terms, if there is an exception thrown in your try
block, you skip directly to the catch
block and do something about it (although, die
is not the best solution).
Yea that seems to be a huge issue. Posts don’t actually show up.
@traq — comment restored (was likely automatically moved to spam folder because it contained more than 3 links).